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:
James Rasell
2025-06-04 14:11:17 +01:00
committed by GitHub
parent 648bacda77
commit 6cf535a86f

View File

@@ -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))