fix(test): poll error counter to 0 before asserting in RecordsMetricsOnSuccess
Race-detector CI runs (-race) slow goroutines enough that a prior sweeper goroutine (e.g. TestStartSweeper_TransientErrorDoesNotCrashLoop) can still be running and incrementing pendingUploadsSweepErrors after metricDelta() captures its baseline, but before the success-path sweeper records its success metrics. 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>
This commit is contained in:
parent
7bc249ff7a
commit
e29b166f60
@ -280,9 +280,16 @@ 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.
|
||||
// Also poll error counter to 0 — with the race detector, a
|
||||
// concurrent sweeper goroutine from a prior test can still be
|
||||
// running and incrementing pendingUploadsSweepErrors after
|
||||
// metricDelta() captures its baseline. Polling to 0 (matching
|
||||
// TestStartSweeper_RecordsMetricsOnError's pattern for the error
|
||||
// path) ensures the error counter has settled before we assert.
|
||||
// Without this, on a slow race-detector host the error counter
|
||||
// from the previous test's sweeper is still in flight when we
|
||||
// read it, producing deltaError=1 instead of 0.
|
||||
waitForMetricDelta(t, deltaError, 0, 2*time.Second)
|
||||
if got := deltaError(); got != 0 {
|
||||
t.Errorf("error counter delta = %d, want 0", got)
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user