consul: Fix data race within test by using mutex to read map. (#25977)

This commit is contained in:
James Rasell
2025-06-04 15:09:37 +01:00
committed by GitHub
parent 6cf535a86f
commit e95148c10d

View File

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