Skip to content

broker test: use fake clock, independent from test speed - #4409

Merged
LKuemmel merged 3 commits into
openWB:masterfrom
LKuemmel:fixes
Dec 1, 2026
Merged

LKuemmel merged 3 commits into
openWB:masterfrom
LKuemmel:fixes

Conversation

@LKuemmel

@LKuemmel LKuemmel commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Der Test war von der Thread-Ausführungsgeschwindigkeit abhängig: Er sendete über echte Timer alle 60 ms eine Nachricht, bei nur 100 ms Nachlaufzeit. Unter CI-Last können Nachrichten später eintreffen, wie zB hier https://github.com/openWB/core/actions/runs/45966919810/job/140397688923?pr=4407

Summary by Sourcery

Decouple broker tests from machine and CI timing so timeout and settle-window behavior is reliably verified.

Enhancements:

  • Make broker timing tests deterministic with a fake clock instead of relying on real timer and thread scheduling.
  • Keep the concurrency test on real synchronization while making its message delivery deterministic and asserting worker threads terminate.

@LKuemmel LKuemmel added the bug Something isn't working label Nov 27, 2026

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 2 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="packages/helpermodules/broker_test.py" line_range="239-240" />
<code_context>
     FakeClient.instances = []
-    incoming = {"x/0/get/#": [(0.0, "x/0/get/power", b"100"), (0.02, "x/0/get/rfid", b'"a"')],
-                "x/1/get/#": [(0.0, "x/1/get/power", b"200"), (0.02, "x/1/get/rfid", b'"b"')]}
+    incoming = {"x/0/get/#": [(0.0, "x/0/get/power", b"100"), (0.0, "x/0/get/rfid", b'"a"')],
+                "x/1/get/#": [(0.0, "x/1/get/power", b"200"), (0.0, "x/1/get/rfid", b'"b"')]}
     created = []

</code_context>
<issue_to_address>
**Concurrent calls run sequentially**

When zero-delay messages are delivered synchronously and the workers are scheduled one after another or the calls are serialized, `subscribe` delivers messages before `on_connect` sets `connected`, and the thread starts lack a barrier, so callback handling can finish before both calls are active and shared-state regressions go undetected.

Synchronize the test and delay message delivery until both collections are active, then release the messages together.
</issue_to_address>

### Comment 2
<location path="packages/helpermodules/broker_test.py" line_range="172" />
<code_context>
 def test_collecting_after_complete_data_is_limited_by_timeout(fake_client):
-    fake_client(incoming=[(i * 0.03, f"x/get/t{i}", b"1") for i in range(40)])
-    start = time.monotonic()
+    clock = fake_client(incoming=[(i * 0.03, f"x/get/t{i}", b"1") for i in range(40)])

     received = broker.publish_and_collect(
</code_context>
<issue_to_address>
**Dropped messages still pass**

When the broker handles only five of the scheduled messages before the deadline, `test_collecting_after_complete_data_is_limited_by_timeout` only requires `5 <= len(received) < 40` at line 179. The fake clock can still reach 0.3 while the broker drops scheduled messages after the first five, so the test passes despite incomplete collection.

Assert the exact expected topic set or count for the deterministic fake-clock schedule.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread packages/helpermodules/broker_test.py Resolved
Comment thread packages/helpermodules/broker_test.py Resolved
@LKuemmel
LKuemmel marked this pull request as draft November 27, 2026 13:46
@LKuemmel
LKuemmel marked this pull request as ready for review November 27, 2026 14:00
@LKuemmel
LKuemmel merged commit 51ab834 into openWB:master Dec 1, 2026
3 checks passed
@LKuemmel
LKuemmel deleted the fixes branch December 1, 2026 14:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant