Theme
Tier 4 · lesson 3 of 10 · 30 min

Keeping the suite fast is a feature you maintain

You will: Keep a suite inside its time budget structurally, and catch the day it drifts out.

Builds on Four layers of test, and what each is for.

A sixty-second budget does not hold itself. It holds because of structural choices — and it breaks the first time someone forgets one.

The marker that does not reach. Simulation tests are marked slow, and make test passes -m "not slow" through colcon. That works for Python packages. But in a CMake-built ROS package, pytest is launched by CTest, which never sees colcon's pytest arguments. The marker is silently ignored, and make test would quietly spend two minutes starting a simulator. So the simulation package registers with CTest only the tests that need no simulator, by name, and make test-sim calls pytest directly with -m slow. Explicit beats clever.

The fix that made it slow. When scenario steps changed from sleeping to polling — the right fix, from Stage 3 — the suite went from 35 seconds to 1 minute 22, past its own budget. The framework's unit tests include four that deliberately assert a false post-condition, to prove a failing step is reported as failing. Under polling, each one now waited out the full 15-second timeout before failing. Correct behaviour, and an expensive test. They now pass timeout=0, and the suite is back at about 33 seconds.

Nobody would have noticed for a while. Every test still passed. The only signal was the clock, which is why the budget is measured every time rather than assumed.

The report that lies. colcon test-result reports every result file under build/, not only this run's. A failure fixed an hour ago kept being reported, and a green lint run looked red. The targets now clear old results first.

In the simulation

The arm has a budget too: no joint may move faster than 1.7434 rad/s, and the controller holds that by structure, on every move, not by hoping. Watch the velocities in /joint_states stay under it. The page shows the speed limit; it does not time any test.

Kinematic: joints move at their real speed limit, but there is no gravity, no load and no physics. That is what the steps below are for.

The SO-101 loads as you reach it.

In this lesson

  1. Open the /joint_states view in the inspector.
  2. Set the step to its largest, 4 of 4 (0.20 rad), and jog any joint once. A 0.20 rad jog takes 0.35 s: read the peak velocity.
  3. Drive shoulder_pan to its upper limit, +110°.
  4. Press h and watch the clock. Home takes 2 s, longer only if a joint would otherwise pass 1.7434 rad/s: from +110° on the pan, just over 2 s. A time that holds because of how the move is built, the way the suite's 60 seconds does.

Do it

  1. Time the suite.

    time make test
    
  2. See which simulation tests CTest is allowed to run, and the comment explaining why.

    sed -n 15,40p src/threevn_sim/CMakeLists.txt
    
  3. Find the four tests that must fail fast.

    grep -n -B3 "timeout=0" src/threevn_control/test/test_scenario_framework.py
    
  4. List the slowest tests in one package.

    make shell
    cd /ws/src/threevn_control && python3 -m pytest test -q --durations=5
    

    Expect: The five slowest tests and their times. None should be more than a second or two.

You will know it worked when: You know your suite's time, and you can explain both ways this project's budget was nearly lost.

When it goes wrong

The suite slowly gets slower, and every test passes.

Why: Something correct but expensive was added — often a timeout being waited out.

Fix: Run with --durations now and then, and treat the budget as a failing test when exceeded.

Terms

Test marker
A label on a test — here slow — used to select or exclude it. Only effective if the runner actually receives the selection.
CTest
CMake's test runner. In CMake-built ROS packages it launches pytest, and does not pass colcon's pytest arguments through.

Every term in the course: glossary.

Check yourself

Answer in your head first, then open it.

Polling is more correct than sleeping. Why did it make the suite slower?

Tests that deliberately assert a false post-condition now waited for the full timeout before failing, where before they failed after one short sleep.

Why register simulation tests with CTest by name instead of relying on the slow marker?

CTest never receives colcon's -m "not slow", so in a CMake package the marker is ignored. Naming the safe tests explicitly does not depend on an argument arriving.

Stretch

Run --durations=10 across every Python package in src/. Find the slowest test in the fast suite and decide whether it belongs there. If it does not, where should it go?

Going deeper