From c4276fcef973f51a3481f8a3352f7d2f17f5c20e Mon Sep 17 00:00:00 2001 From: yujiezhang-ops Date: Fri, 20 Nov 2026 11:14:24 +0800 Subject: [PATCH] test: probe the write lock from one request at a time TestModelCheckRunsWithTheWriteLockReleased asks, from inside each probe, whether writeMu can be taken, by taking it for an instant. The protocols are probed concurrently, so one probe's own attempt was sometimes what another probe found held, and the test reported the lock as held during the check when it was not. Under -race it failed 17 times in 300 runs before this change and none in 1000 after. It has failed on main and on an unrelated pull request. Co-Authored-By: Claude Sonnet 5 --- internal/app/profile_model_check_test.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/internal/app/profile_model_check_test.go b/internal/app/profile_model_check_test.go index 024eb884..a99fdb8e 100644 --- a/internal/app/profile_model_check_test.go +++ b/internal/app/profile_model_check_test.go @@ -336,8 +336,14 @@ func TestModelCheckRunsWithTheWriteLockReleased(t *testing.T) { core := gatewayCore(t, gateway) var heldDuringProbe atomic.Bool var probed atomic.Bool + // The protocols are probed concurrently, and the TryLock below takes the + // lock for an instant. Without this, one probe's own attempt is what another + // probe finds held. + var oneProbeAtATime sync.Mutex gateway.mu.Lock() gateway.onRequest = func() { + oneProbeAtATime.Lock() + defer oneProbeAtATime.Unlock() probed.Store(true) if !core.writeMu.TryLock() { heldDuringProbe.Store(true)