Skip to content

test: prove the controller stepped before refuting its output - #120

Merged
jimsynz merged 1 commit into
mainfrom
test/event-driven-tests
Oct 14, 2026
Merged

jimsynz merged 1 commit into
mainfrom
test/event-driven-tests

Conversation

@jimsynz

@jimsynz jimsynz commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

What was timing-based

Three tests in test/bb/pid/controller_test.exs used refute_receive {:bb, [:actuator, :base_link, :joint1, :servo], _}, 50 to stand in for "the controller didn't publish":

  • "controller filters messages by type"
  • "controller does not publish when only setpoint is received"
  • "controller does not publish when only measurement is received"

Fifty milliseconds is about five ticks at 100 Hz, but nothing proved the inputs had been consumed or that a tick had stepped in that window. Under load the tests would pass without testing anything.

What they wait on now

A shared refute_output_after_a_step/0 helper:

  1. :sys.get_state/1 on the controller, so the published inputs have been handled (BB.PubSub.publish/3 sends from the test process).
  2. Attaches a [:bb, :loop, :tick] telemetry handler filtered on robot: TestRobot, path: [:test_pid]. It is attached after the sync, so any event it reports comes from a tick that saw the inputs. BB.Loop only emits on ticks with a dt, which are the ones that reach step/2.
  3. assert_receives that event (1 s upper bound), then :sys.get_state/1 again so that tick's step/2 has finished. Anything it published reached the test before the reply.
  4. refute_received the output, which checks the mailbox without waiting.

As a check that the helper isn't vacuous, I temporarily added a measurement to the setpoint-only test. It then failed on refute_received 3/3 times. No lib changes.

The assert_receive …, 100 calls elsewhere in the file are upper bounds on an output that must arrive, so I left them alone.

Left

Nothing.

Results

  • The three converted tests, mix test test/bb/pid/controller_test.exs:174 :201 :218 --seed 0 ×10: 10/10 runs passed (3 tests each).
  • mix check --no-retry: all green, before and after the change. No pre-existing failures.

@jimsynz
jimsynz force-pushed the test/event-driven-tests branch from 7397803 to 5f37809 Compare October 13, 2026 22:18
@jimsynz
jimsynz merged commit ad6d996 into main Oct 14, 2026
17 checks passed
@jimsynz
jimsynz deleted the test/event-driven-tests branch October 14, 2026 20:57
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.

1 participant