Repository navigation
broker test: use fake clock, independent from test speed - #4409
Merged
Merged
Conversation
There was a problem hiding this comment.
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>
LKuemmel
marked this pull request as draft
November 27, 2026 13:46
LKuemmel
marked this pull request as ready for review
November 27, 2026 14:00
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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: