mirror of
https://github.com/kemko/nomad.git
synced 2026-01-06 18:35:44 +03:00
drainer: Fix data race within test by correctly copying alloc. (#25975)
Some test cases were writing the same allocation object (memory pointer) to Nomad state in subsequent upsert calls. This causes a race condition with the drainer job watcher which reads the same object from Nomad state to perform conditional checks. The data race is fixed by ensuring the allocation is copied between writes.
This commit is contained in:
@@ -193,7 +193,7 @@ func TestDrainingJobWatcher_DrainJobs(t *testing.T) {
|
||||
replacement.NodeID = runningNode.ID
|
||||
// start in pending state with no health status
|
||||
|
||||
updates = append(updates, a, replacement)
|
||||
updates = append(updates, a.Copy(), replacement)
|
||||
replacements[i] = replacement.Copy()
|
||||
}
|
||||
must.NoError(t, store.UpsertAllocs(structs.MsgTypeTestSetup, index, updates))
|
||||
@@ -254,7 +254,7 @@ func TestDrainingJobWatcher_DrainJobs(t *testing.T) {
|
||||
a.ClientStatus = structs.AllocClientStatusComplete
|
||||
|
||||
replacement := newAlloc(runningNode, a.Job)
|
||||
updates = append(updates, a, replacement)
|
||||
updates = append(updates, a.Copy(), replacement)
|
||||
replacements[i] = replacement.Copy()
|
||||
}
|
||||
must.NoError(t, store.UpsertAllocs(structs.MsgTypeTestSetup, index, updates))
|
||||
@@ -298,7 +298,7 @@ func TestDrainingJobWatcher_DrainJobs(t *testing.T) {
|
||||
a.ClientStatus = structs.AllocClientStatusComplete
|
||||
|
||||
replacement := newAlloc(runningNode, a.Job)
|
||||
updates = append(updates, a, replacement)
|
||||
updates = append(updates, a.Copy(), replacement)
|
||||
replacements[i] = replacement.Copy()
|
||||
}
|
||||
must.NoError(t, store.UpsertAllocs(structs.MsgTypeTestSetup, index, updates))
|
||||
|
||||
Reference in New Issue
Block a user