From 5f36958da430b21c05d9968627114e6c02f0ce8d Mon Sep 17 00:00:00 2001 From: "denis.bilenko" Date: Thu, 19 Nov 2026 11:56:31 +0000 Subject: [PATCH] Fix flaky TestRecordKeepsConcurrentOptOut: give queued writers a longer lock wait The test starts 21 writers that take the state lock one at a time. Each waits at most stateLockWait (1s) for it; on slow runners (Windows, ~180ms per locked read and rename) the last writers give up with 'held by another CLI process'. Make stateLockWait a var and raise it in this test. Co-authored-by: Isaac --- libs/aitools/autoinstall/run.go | 8 ++++---- libs/aitools/autoinstall/run_test.go | 7 +++++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/libs/aitools/autoinstall/run.go b/libs/aitools/autoinstall/run.go index 78a7298085e..e19c95130d8 100644 --- a/libs/aitools/autoinstall/run.go +++ b/libs/aitools/autoinstall/run.go @@ -35,10 +35,6 @@ const ( // and rewritten. stateLockFileName = "auto-install.json.lock" - // stateLockWait bounds the wait for the state lock. A live holder keeps it - // only to read or rewrite a small file. - stateLockWait = time.Second - // lockRetryInterval is how often a held lock is tried again. lockRetryInterval = 10 * time.Millisecond ) @@ -181,6 +177,10 @@ func lock(ctx context.Context, name string, wait time.Duration) (unlock func(), } } +// stateLockWait bounds the wait for the state lock. A live holder keeps it +// only to read or rewrite a small file. Tests that queue many holders raise it. +var stateLockWait = time.Second + // errLockHeld is the error of tryLockFile when another process holds the lock. var errLockHeld = errors.New("held by another CLI process") diff --git a/libs/aitools/autoinstall/run_test.go b/libs/aitools/autoinstall/run_test.go index 33e7b48332f..9718440887d 100644 --- a/libs/aitools/autoinstall/run_test.go +++ b/libs/aitools/autoinstall/run_test.go @@ -29,6 +29,13 @@ func TestTryLockExcludesOtherRuns(t *testing.T) { func TestRecordKeepsConcurrentOptOut(t *testing.T) { ctx := env.WithUserHomeDir(t.Context(), t.TempDir()) + // The 21 writers take the lock one at a time, and on a slow runner each + // holds it long enough that the last ones would give up after the + // default wait. + orig := stateLockWait + t.Cleanup(func() { stateLockWait = orig }) + stateLockWait = time.Minute + // Without the state lock, a Record that read the state before the opt-out // was saved would write opted_out=false back. var wg sync.WaitGroup