Skip to content

test(node): probe_rate_limit_returns_rate_limited_close_code flakes under nextest #691

Closed

Description

@thiras

Context

Surfaced during PR #684 verification: the test probe_rate_limit_returns_rate_limited_close_code flakes under cargo nextest run but passes reliably under cargo test. The failure is unrelated to the contract changes in #684, so it was not addressed there.

Repro

cargo nextest run -p decdn-node probe_rate_limit_returns_rate_limited_close_code

Compare against:

cargo test -p decdn-node probe_rate_limit_returns_rate_limited_close_code

Likely cause: nextest's per-test process isolation interacts with the dispatch rate limiter's wall-clock window in a way that the in-process test runner does not. Suspects to investigate:

  • Test relies on a real time interval and nextest's startup overhead pushes the assertion past the window edge.
  • Shared global state (e.g. a static limiter cell) initialized at a different point in the two harnesses.
  • A tokio::time::pause/advance boundary that fires before the rate-limit check.

Acceptance

  • Test passes reliably under both cargo nextest run and cargo test.
  • If the fix is to fake the clock, use tokio::time::pause consistently across the rate-limit test surface so no other test in the same file regresses.

References

Activity

  1. added
    kind:bug
    rust
    kind:test
    on May 28, 2026
  2. github-actions commented on May 28, 2026

    @github-actions

    🎯 Triage report

    A test for the dispatch rate limiter is flaky exclusively under cargo nextest (per-process isolation) but passes under cargo test. The issue is well-scoped: the author identified three concrete suspects (wall-clock window edge, static state init timing, tokio::time boundary) and provided clear acceptance criteria. Surfaced as a side-effect of PR #684 verification, so it's not blocking that PR but is a CI reliability concern.

    📊 Assessment

    Dimension Value Reasoning
    Type Bug A test that passes under one harness but fails under another is a test reliability defect
    Labels bug, rust, testing (already applied) All three pre-existing labels are correct; medium priority would be appropriate as it affects CI reliability but isn't blocking
    Coding agent Suitable Requirements are precise, repro commands are provided, acceptance criteria are well-defined, scope is fully self-contained within crates/node
    💡 Notes and suggestions

    Root cause investigation order:

    1. Check for wall-clock dependency first — search the test for std::time::Instant, Duration::from_millis, or sleep. Any real-time sleep in a nextest environment is inherently flaky because nextest spins up a fresh process (with its own tokio runtime) per test, adding startup jitter.

    2. Check for static or once_cell rate limiter state — if the limiter is held in a static LazyLock<...> or similar, it is initialized fresh per-process under nextest (correct) but may carry state from a prior test under cargo test in-process. This could explain why cargo test always passes — a prior test may have reset the window.

    3. tokio::time::pause / advance audit — if any other test in the same file calls tokio::time::pause and the probe test runs after it under cargo test (but before it under nextest due to ordering), the clock state differs.

    Recommended fix pattern:

    #[tokio::test]
    async fn probe_rate_limit_returns_rate_limited_close_code() {
        tokio::time::pause(); // freeze wall clock
        // ... set up limiter with a known window ...
        tokio::time::advance(window_duration + margin).await;
        // ... assert rate-limited close code ...
    }

    Use tokio::time::pause() + advance() consistently across all rate-limit tests in the file, as the issue author notes. This eliminates real-time dependency entirely.

    Sub-task checklist:

    • Locate the test in crates/node/src/ (likely dispatch.rs or a tests/ submodule)
    • Audit all time dependencies in the test (real Instant, sleep, Duration)
    • Replace wall-clock usage with tokio::time::pause + advance
    • Confirm no other test in the same file breaks (run cargo nextest run -p decdn-node for the full file)
    • Verify both cargo nextest run and cargo test pass reliably

    Generated by Agentic Triage for issue #691 · ● 1.8M · ◷

    Add this agentic workflows to your repo

    To install this agentic workflow, run

    gh aw add githubnext/agentics/workflows/issue-triage.md@94ec5db57374c5b04a4b8eef8b4413f9af44d63f
    
  3. self-assigned this
    on May 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind:bugkind:testrust

Type

Fields

Priority

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions