Skip to content

Navigation Menu

Sign in
Sign up

test: deflake TestTryAcquire/refills_tokens_correctly (timing-sensitive) #35

Open
Labels
bugSomething isn't working

Description

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).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      AltStyle によって変換されたページ (->オリジナル) /