spring-projects / spring-statemachine

Spring Statemachine is a framework for application developers to use state machine concepts with Spring.
1.54k stars 607 forks source link

StateMachineListener Not Notified Of Each State Change #1096

Open mroeppis opened 1 year ago

mroeppis commented 1 year ago

Issue Setting

Consider this simple Statemachine with 3 states and 1 event:

START -(NEXT)-> IN_BETWEEN -> END

The use case here is:

  1. start the machine
  2. send event NEXT

The machine runs with a StateMachineListener.

Version Specifics

The issue mainly concerns Spring Statemachine Core 3.2.0 but points out something that might be wrong as well with version 2.5.1.

Issue Description

The method StateMachineListener#stateChanged( from, to) is called differently in version 2.5.1 and 3.2.0.

I attached a MWE with a test for reference (built with Gradle 7.5.1 and JDK 17.0.6).

Version 2.5.1

The listener is notified of each state change, i.e. 3 times. But the order of notification is not the order of change:

  1. null->START
  2. IN_BETWEEN->END
  3. START->IN_BETWEEN

Keeping order is important if the listener must prepare something for an upcoming state change.

Version 3.2.0

The listener misses one notification, i.e. the first state change after the event is sent:

  1. null->START
  2. IN_BETWEEN->END

Expected Behavior

The listener should be notified of all state changes in order:

  1. null->START
  2. START->IN_BETWEEN
  3. IN_BETWEEN->END