Unhandled Events, Not Broken States, Are What Kill Your State Machine
You probably test a state machine by walking the paths you believe are legal: an order moves from pending to paid, then to shipped, and finally to delivered. That test passes and tells you very little, because the failures that actually freeze a service tend to come from the cells you never filled in. A missing transition is worse than a wrong transition; the wrong one at least throws an…
The article emphasizes that the real issues in state machines often stem from unhandled events rather than broken states. While it may seem intuitive to test the legal paths of a state machine, such as an order moving from pending to paid, the failures that typically freeze a service occur in the cells that are never filled in. A missing transition is worse than a wrong transition, as the latter at least throws an exception that can be logged, while the undefined one often falls through to a default branch that silently returns the current state and reports success.
This issue becomes more pronounced when the state machine is drafted by a model, which may not account for edge cases like a cancel event after an order has already shipped. The article suggests starting from the contract rather than a vague request to attack the machine, focusing on ensuring every combination of state and event has an explicit owner, even if the owner is a rejection.
This clarity can be achieved by using cheap compute for enumeration and a free model to suggest which cells should refuse the event instead of handling it.
Brief written by urgent.news from Dev.to's own syndicated text. Machine-written — may contain errors; check the original before relying on it.