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