dotnet-state-machine / stateless

A simple library for creating state machines in C# code
Other
5.53k stars 765 forks source link

Graph: re-entry transition is missing its entry action #588

Open nightroman opened 3 months ago

nightroman commented 3 months ago

Here is the graph of the official BugTrackerExample

Graphviz

Note that it correctly shows the label Assign / OnAssigned on transitioning from Open to Assigned and from Deferred to Assigned.

But on transitioning from Assigned to Assigned (re-entry) the label is just Assign instead of expected Assign / OnAssigned. (OnAssigned is called on re-entry to Assigned and this should be reflected).

mclift commented 3 months ago

Thanks for writing this up, @nightroman.

I think that in this case the graph output is correct since OnAssigned is specifically configured for the parameterised Assign trigger, whereas the re-entrant transition uses the Assign trigger directly.

https://github.com/dotnet-state-machine/stateless/blob/d58e33b7b777a613fa1096253f8921db9190cdd4/example/BugTrackerExample/Bug.cs#L42-L43

Does this explain what you're seeing?

Thanks

nightroman commented 3 months ago

On transitioning from Assigned to Assigned (re-entry) the parameterized trigger Assign is called, i.e. one has to specify the new bug assignee. E.g. when assigning from Harry to Fred here, we provide the parameter "Fred":

https://github.com/dotnet-state-machine/stateless/blob/d58e33b7b777a613fa1096253f8921db9190cdd4/example/BugTrackerExample/Program.cs#L13-L14

In other words, .PermitReentry(Trigger.Assign) does not mean that the re-entry is not parameterized. The same parameterized .OnEntryFrom(_assignTrigger, OnAssigned) applies and the call to OnAssigned is happening on re-entry (debugging, testing, logging confirm this).

mclift commented 3 months ago

Thanks for the quick reply. I really shouldn't try to debug stuff when I'm tired :)

I'll try to spend some time on this over the next few days, unless you're already working on it.

Thanks

nightroman commented 3 months ago

@mclift Thank you. No, I am not working on this (yet, maybe another day and another issue). Besides, this issue may be related or be in the same area as #587 and you have already started some work #589 (great!). So it might be reasonable either to fix both issues together or one after another.

nightroman commented 2 months ago

As for contributing, in a way... at this point I've been working on PowerShell helpers for Stateless: https://github.com/dotnet-state-machine/stateless/discussions/592 These tools are useful for state machine interactive testing, low ceremony graph generation/show, etc.