From e95148c10debe186d771f21834a0651b6dcf8a6b Mon Sep 17 00:00:00 2001 From: James Rasell Date: Wed, 4 Jun 2025 15:09:37 +0100 Subject: [PATCH] consul: Fix data race within test by using mutex to read map. (#25977) --- command/agent/consul/unit_test.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/command/agent/consul/unit_test.go b/command/agent/consul/unit_test.go index e2d53fce8..123770f58 100644 --- a/command/agent/consul/unit_test.go +++ b/command/agent/consul/unit_test.go @@ -404,8 +404,11 @@ func TestConsul_ShutdownBlocked(t *testing.T) { } require.NoError(ctx.ServiceClient.RegisterAgent("client", agentServices)) require.Eventually(ctx.ServiceClient.hasSeen, time.Second, 10*time.Millisecond) + + ctx.FakeConsul.mu.Lock() require.Len(ctx.FakeConsul.services["default"], 1, "expected agent service to be registered") require.Len(ctx.FakeConsul.checks["default"], 1, "expected agent check to be registered") + ctx.FakeConsul.mu.Unlock() // prevent normal shutdown by blocking Consul. the shutdown should wait // until agent deregistration has finished