mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-10-06 07:15:09 +00:00
fix(web): a cancelled on-demand start never reaches the display after its replacement
CI caught a race in test_a_new_start_supersedes_the_pending_one: the dispatcher's worker could read the old start, the route cancel it and send the new one, and the worker's send of the old one land after it. cancel() now waits out a send already in flight (the worker holds a send lock while it reads the pending start and sends it), so whatever the caller sends next lands after it. Pinned by test_a_cancel_waits_for_a_send_in_flight, which fails without the wait. The Linux-only TestRealSocket test for a display that went away now expects the 202 and the start-timeout that follows, as the route answers since the background dispatcher. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -204,6 +204,29 @@ class TestOneAtATime:
|
||||
status = d.status()
|
||||
assert status["status"] == "idle" and status["last_event"] == "requested-stop"
|
||||
|
||||
def test_a_cancel_waits_for_a_send_in_flight(self, make):
|
||||
# Whatever the caller sends after cancel() must land after the
|
||||
# cancelled start, not race it to the display.
|
||||
in_flight, release = threading.Event(), threading.Event()
|
||||
|
||||
def slow(payload):
|
||||
in_flight.set()
|
||||
release.wait(5)
|
||||
raise _not_listening()
|
||||
|
||||
send = FakeSend(slow)
|
||||
d = make(send)
|
||||
d.submit(_payload("old"))
|
||||
assert in_flight.wait(5)
|
||||
done = threading.Event()
|
||||
threading.Thread(target=lambda: (d.cancel("superseded"), done.set()),
|
||||
daemon=True).start()
|
||||
assert not done.wait(0.1), "cancel returned while the old send was in flight"
|
||||
release.set()
|
||||
assert done.wait(5)
|
||||
assert _settled(d)
|
||||
assert send.sent == ["old"]
|
||||
|
||||
def test_a_cancel_with_nothing_pending_does_nothing(self, make):
|
||||
d = make(FakeSend("ack"))
|
||||
assert d.cancel() is None
|
||||
|
||||
Reference in New Issue
Block a user