Compare commits

...

1 Commits

Author SHA1 Message Date
core-fe e522547035 fix(test): poll error counter to 0 before asserting in RecordsMetricsOnSuccess
Secret scan / Scan diff for credential-shaped strings (pull_request) Successful in 4s
sop-tier-check / tier-check (pull_request) Failing after 4s
audit-force-merge / audit (pull_request) Has been skipped
Race-detector CI runs (-race) are slow enough that a prior sweeper
goroutine (TestStartSweeper_TransientErrorDoesNotCrashLoop) may still
be running and incrementing pendingUploadsSweepErrors after
RecordsMetricsOnSuccess captures its metricDelta() baseline, but before
the success-path assertion. The test then reads deltaError=1 instead
of 0.

Fix: add waitForMetricDelta(t, deltaError, 0, 2*time.Second) before
the assertion, matching the polling pattern already used in the
error-path test (TestStartSweeper_RecordsMetricsOnError). This
ensures the error counter has settled before we assert on it.

Fixes molecule-core#22.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-09 23:22:48 +00:00
@@ -280,9 +280,13 @@ func TestStartSweeper_RecordsMetricsOnSuccess(t *testing.T) {
// vs-metric-record race (see waitForMetricDelta comment).
waitForMetricDelta(t, deltaAcked, 3, 2*time.Second)
waitForMetricDelta(t, deltaExpired, 5, 2*time.Second)
// Error counter MUST stay at zero on the success path. Read after
// the success counters have settled — once those are correct,
// StartSweeper has fully processed this cycle's result.
// Error counter MUST stay at zero on the success path. Poll for it to
// settle first — a goroutine from a prior test (e.g.
// TestStartSweeper_TransientErrorDoesNotCrashLoop) may still be running
// and incrementing errorCount after its metricDelta() baseline was
// captured. This race manifests as deltaError=1 on success-path
// assertions in slow -race CI runs (#22 fix).
waitForMetricDelta(t, deltaError, 0, 2*time.Second)
if got := deltaError(); got != 0 {
t.Errorf("error counter delta = %d, want 0", got)
}