Skip to content

Fix the race in the persisted global downloads integration test #2953

Closed

Description

@josecelano-bot

Summary

The tracker-core integration test it_should_persist_the_global_number_of_completed_peers_into_the_database is flaky. It failed once during the maintainer's merge-script pre-push run of all tests on develop (while merging #2946, a docs-only PR):

panicked at packages/tracker-core/tests/integration.rs:253:5:
assertion `left == right` failed
  left: 0
 right: 1

Cause

The background event listener (increase_global_downloads in packages/tracker-core/src/statistics/event/handler.rs) awaits the database write of the global downloads count first, and only then increments the in-memory counter tracker_core_persisted_torrents_downloads_total. The test helper TestEnv::wait_for_global_downloads_persisted (packages/tracker-core/tests/common/test_env.rs) waits for the database value only. If the test reads the counter after the database write but before the increment, it reads 0.

The production code is correct: the counter counts downloads that were actually persisted, so it must follow the database write. Only the test's wait condition is wrong.

Reproduction

  • 300 runs of the test alone and 100 runs of the whole integration binary on develop all passed: the window is very short.
  • A temporary 300 ms sleep between the database write and the counter increment reproduces the exact failure (integration.rs:253:5, left: 0, right: 1).

Proposed fix

Make wait_for_global_downloads_persisted wait, within its existing 5-second timeout, until both the database value and the in-memory counter reach the expected value. No production code changes. No other test has the same race (the spec lists every test that reads the counter and why it is safe).

Specification

Spec-first: docs/issues/open/<number>-fix-persisted-downloads-integration-test-race/ISSUE.md with issue-local manual-verification-evidence.md, added in a spec-only PR before the implementation PR.

Activity

  1. added 14 commits that reference this issue on Nov 18, 2026
  2. 4 remaining items

  3. added 6 commits that reference this issue on Nov 19, 2026
  4. added 3 commits that reference this issue on Nov 19, 2026
  5. added a commit that references this issue on Nov 19, 2026
  6. added 2 commits that reference this issue on Nov 19, 2026
  7. added 2 commits that reference this issue on Nov 20, 2026
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions