From 9a25e89b00f4cefa97c4edfc42a066fcefa32ca7 Mon Sep 17 00:00:00 2001 From: James Rasell Date: Fri, 11 Jun 2021 11:55:21 +0200 Subject: [PATCH] deploymentwatcher: fix test data race. --- nomad/deploymentwatcher/deployments_watcher_test.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/nomad/deploymentwatcher/deployments_watcher_test.go b/nomad/deploymentwatcher/deployments_watcher_test.go index 71ab0f8a2..64fc6a724 100644 --- a/nomad/deploymentwatcher/deployments_watcher_test.go +++ b/nomad/deploymentwatcher/deployments_watcher_test.go @@ -614,8 +614,17 @@ func TestWatcher_AutoPromoteDeployment(t *testing.T) { // Start the deployment w.SetEnabled(true, m.state) - testutil.WaitForResult(func() (bool, error) { return 1 == len(w.watchers), nil }, - func(err error) { require.Equal(t, 1, len(w.watchers), "Should have 1 deployment") }) + testutil.WaitForResult(func() (bool, error) { + w.l.RLock() + defer w.l.RUnlock() + return 1 == len(w.watchers), nil + }, + func(err error) { + w.l.RLock() + defer w.l.RUnlock() + require.Equal(t, 1, len(w.watchers), "Should have 1 deployment") + }, + ) // Mark the canaries healthy req := &structs.DeploymentAllocHealthRequest{