Skip to content

Commit bbe21b0

Browse files
tae2089claude
andauthored
test: fix flaky TestStatusHandler_RecentRepos_FailureHasErrorFields (#24)
The test waited on `len(RecentRepos) > 0`, but a repo is tracked (and thus present in RecentRepos) as soon as processing starts — before the handler returns and the queue records last_error/last_error_time. Under load the status snapshot could be read in that window, so `last_error` came back empty. Wait on the actual recorded signal instead: `RecentRepos[0].LastError != ""` for the failure test, and `!RecentRepos[0].LastSuccessTime.IsZero()` for the sibling success test (TestStatusHandler_ReportsPerRepoRecentRepos), which had the same latent race against `last_success_time`. Reproduced reliably with `-race`; fixed test now passes 40x under `-race`. Production sync-queue code is unchanged. Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
1 parent cd6877d commit bbe21b0

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

cmd/ccg/health_test.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,8 +373,11 @@ func TestStatusHandler_ReportsPerRepoRecentRepos(t *testing.T) {
373373
t.Fatal("timed out waiting for handler")
374374
}
375375

376+
// The repo appears in RecentRepos as soon as it is tracked, before the handler
377+
// returns and the success time is recorded. Wait for the recorded success.
376378
for deadline := time.Now().Add(2 * time.Second); time.Now().Before(deadline); {
377-
if len(q.Stats().RecentRepos) > 0 {
379+
rr := q.Stats().RecentRepos
380+
if len(rr) > 0 && !rr[0].LastSuccessTime.IsZero() {
378381
break
379382
}
380383
time.Sleep(10 * time.Millisecond)
@@ -434,8 +437,11 @@ func TestStatusHandler_RecentRepos_FailureHasErrorFields(t *testing.T) {
434437
t.Fatal("timed out waiting for handler")
435438
}
436439

440+
// The repo appears in RecentRepos as soon as it is tracked, before the handler
441+
// returns and the failure (last_error) is recorded. Wait for the recorded error.
437442
for deadline := time.Now().Add(2 * time.Second); time.Now().Before(deadline); {
438-
if len(q.Stats().RecentRepos) > 0 {
443+
rr := q.Stats().RecentRepos
444+
if len(rr) > 0 && rr[0].LastError != "" {
439445
break
440446
}
441447
time.Sleep(10 * time.Millisecond)

0 commit comments

Comments
 (0)