Context
During the module-rename PR (#34) CI run, TestTryAcquire/refills_tokens_correctly failed once on macos-latest / Go 1.22 and passed on rerun — it is timing-sensitive, not related to any code change.
Evidence
internal/api/ratelimit_test.go:184 — the test sleeps 55ms and asserts exactly one token was refilled within a 100ms window (Should be false assertion at line 197). When the CI runner's sleep overshoots, a second token refills and the assertion fails. Failure observed in run 29396050341; green after gh run rerun --failed.
Suggested fix
Refactor the rate limiter to accept an injectable clock (or now func() time.Time) so the test can advance time deterministically; alternatively widen the tolerance to assert >= 1 token refilled within the window. The fake-clock approach also unblocks deterministic tests for retry backoff (see #31).
Context
During the module-rename PR (#34) CI run,
TestTryAcquire/refills_tokens_correctlyfailed once on macos-latest / Go 1.22 and passed on rerun — it is timing-sensitive, not related to any code change.Evidence
internal/api/ratelimit_test.go:184— the test sleeps 55ms and asserts exactly one token was refilled within a 100ms window (Should be falseassertion at line 197). When the CI runner's sleep overshoots, a second token refills and the assertion fails. Failure observed in run 29396050341; green aftergh run rerun --failed.Suggested fix
Refactor the rate limiter to accept an injectable clock (or
now func() time.Time) so the test can advance time deterministically; alternatively widen the tolerance to assert>= 1token refilled within the window. The fake-clock approach also unblocks deterministic tests for retry backoff (see #31).