Skip to content

wait for the stack under test before playing the bag - #41

Open
Sunart24 wants to merge 5 commits into
polymathrobotics:mainfrom
kiwicampus:kiwi-main
Open

Sunart24 wants to merge 5 commits into
polymathrobotics:mainfrom
kiwicampus:kiwi-main

Conversation

@Sunart24

Copy link
Copy Markdown

feat: wait for the stack under test before playing the bag

The recorder, the test's launch and the player all started at the same instant,
so on a short fixture the bag could finish before the nodes under test existed.
The run was then recorded without the very topics the test exists to capture,
and it surfaced as an empty analyze rather than as a startup race. Playback now
waits for the stack to come up first.

Found while building a replay test whose fixture is under a second, along with
three other things that only show up on a real bag.

  • wait_for_stack — a gate process, on by default, that holds the player
    until either every expected output topic has a publisher, or something
    subscribes to /clock. The second condition is what makes it work: a node on
    sim time creates nothing until /clock arrives, and /clock only arrives
    with the player, so waiting on its outputs deadlocks against the very thing
    being gated.
  • --output-dir — results were written to the system temp directory and
    lost on restart. Also exported as REPLAY_TESTING_OUTPUT_DIR so a test can
    put its own artifacts with the run. Fixes a related bug: os.access() is
    false for a path that does not exist yet, so the write-permission probe
    silently redirected every run to ./test_results.
  • A fresh reader per analyze test — rosbag2_py readers cannot be rewound,
    so one shared reader left every test after the first reading an empty bag.
  • Input validation counts messages — a topic can be declared in a bag and
    carry nothing. Missing topics still raise; a declared but silent topic is now
    reported and the run continues.
  • RegeneratedSource / ReplaySourcePlan — a helper for inputs a bag
    cannot supply as recorded. A test declares each case once, with its reason,
    and derives the required topics, what to strip, and the launch flags.

Tests: 32, including 4 for the gate and 14 for the source plan.

Migration Guide

Nothing to change for an existing test, with one exception.

The gate is on by default and waits up to 30 s. A test whose stack neither
publishes its declared outputs nor subscribes to /clock will now spend that
timeout before playback, then carry on with a warning. If that is your case:

ReplayRunParams(runner_args=RunnerArgs(wait_for_stack=False))

wait_for_stack_timeout (30.0) and wait_for_stack_grace (2.0) are also
available.

To keep results somewhere durable:

replay_test my_test.py --output-dir /path/to/results

@Sunart24 Sunart24 changed the title Kiwi main wait for the stack under test before playing the bag Sep 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants