Repository navigation
fix: answer callers of events dropped when the machine terminates - #685
Merged
Merged
Conversation
Once the machine reaches a top-level final state, external events still queued are dropped. Their futures were never resolved, so a coroutine awaiting send() of one hung forever on the async engine. The processing loop now drains the external queue when the machine stops and answers each caller as the stopped machine answers a new event: None, or TransitionNotAllowed when allow_event_without_transition is False. A machine stopped during a macrostep, by an eventless or internal transition to a top-level final state or by a top-level parallel state completing, still took one more queued external event in the same iteration; the loop now stops there. Fixes #678 Signed-off-by: Fernando Macedo <fgmacedo@gmail.com>
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #685 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 53 53
Lines 5787 5808 +21
Branches 918 925 +7
=========================================
+ Hits 5787 5808 +21
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.



Fixes #678
Why
On the async engine, 3 of 3 coroutines awaiting
send()of an event queued behind one that reaches a top-level final state hang forever onmain(repro below). v3.2.1 answered them withNone(StateChart) orTransitionNotAllowed(StateMachine). The regression came from #668, which stops the loop at termination and leaves the dropped triggers' futures pending.What changes
None, orTransitionNotAllowedfor its own event whenallow_event_without_transitionisFalse.maina syncStateMachineraisedTransitionNotAllowedfor it, and a completed root parallel state ran it and re-entered the parallel.StateChart.Evidence
New tests in
tests/test_async_futures.py::TestEventsDroppedAtFinalState(14, withpytest.mark.timeout(5), sync and async viasm_runner). Without the engine changes:With them:
Repro (a
finishholding the lock, twogoand onegowithdelay=1000queued behind it), per version:repro script
Not verified
catch_errors_as_events=False) still leaves other coroutines' futures pending on bothmainand this branch; v3.2.1 answered them withNone. Out of scope here, to be tracked separately.put()on aStateMachinewhose event is dropped now logs "Future exception was never retrieved", as an event rejected while processed already does.engine.stop()(invoke cancellation) takes the same drain path but has no dedicated test.