Replace the fixed listener-start sleep in the tracker-core TestEnv

Open
#2,986 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
52/100
Issue type
Refactor
Clarity
Clearly specified
Activity status
Active
Tech stack
rust
Domain
testing-qa

Research direction

Start in packages/tracker-core/tests/common/test_env.rs at TestEnv::run_jobs, noting where each listener calls event_bus.receiver() relative to the spawn, then read packages/events/src/broadcaster.rs to confirm the broadcast channel buffers for subscribers. Decide whether subscription alone means ready (remove the sleep with a comment explaining why) or whether a bounded readiness signal is needed, and write the spec first per the repo workflow. Done when the sleep is gone and repeated runs of a listener-dependent test (and the whole integration binary) pass.

Written by the indexing model from the issue text.

Description

Problem

TestEnv::run_jobs in packages/tracker-core/tests/common/test_env.rs spawns the tracker-core integration-test event listeners (swarm statistics, in-memory statistics and, with persistence, persistent completed statistics) and then sleeps a fixed 100 ms:

// Give the event listeners some time to start
// todo: they should notify when they are ready
tokio::time::sleep(std::time::Duration::from_millis(100)).await;

A fixed sleep is a timing guess. It adds 100 ms to every started TestEnv (some tests start two to simulate a restart), and on a loaded host it either is not needed or is not enough. #2953 was a race of the same kind in this test environment: a wait that assumed the background task had finished. It failed once in the maintainer's merge-script pre-push run.

What to find out first

Each listener gets its receiver from event_bus.receiver() synchronously in run_jobs, before the task is spawned, and the bus is a tokio::sync::broadcast channel (packages/events/src/broadcaster.rs). If subscribing is all a listener needs to "be ready", events sent after run_jobs returns are already buffered for it, and the sleep can be removed. If something else must happen first, TestEnv needs a readiness signal (for example the listener reports when it has started) instead of the sleep.

Done when

  • The fixed sleep in run_jobs is gone: either it is removed with a recorded reason why the listeners are ready when run_jobs returns, or it is replaced by an explicit readiness signal with a bounded wait.
  • The tracker-core integration test binary still passes on repeated runs (for example 300 runs of a listener-dependent test and 100 runs of the whole binary, as in #2953).
  • No production behavior changes unless the investigation shows a readiness signal is needed in the listener API; if so, the spec says so.

Found while working on #2953 (PRs #2954, #2964, #2970). The spec comes first, per the repository's spec-first workflow.

Dominant language
Rust
Stars
532
Forks
56
Avg merge
11h 20m
Merged PRs (30d)
282

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from torrust/torrust-tracker

All issues in torrust/torrust-tracker

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.