3636import io .serverlessworkflow .impl .persistence .PersistenceInstanceHandlers ;
3737import io .serverlessworkflow .impl .persistence .WorkflowPersistenceInstance ;
3838import java .io .IOException ;
39+ import java .time .Duration ;
3940import java .time .Instant ;
4041import java .util .Map ;
4142import java .util .Optional ;
@@ -55,6 +56,7 @@ public abstract class AbstractHandlerPersistenceTest {
5556 protected WorkflowModel context ;
5657 protected WorkflowInstanceData workflowInstance ;
5758 protected WorkflowContextData workflowContext ;
59+ private Instant beforeStart ;
5860
5961 @ BeforeAll ()
6062 static void init () throws IOException {
@@ -64,14 +66,15 @@ static void init() throws IOException {
6466
6567 @ BeforeEach
6668 void setup () {
69+ beforeStart = Instant .now ();
6770 handlers = getPersistenceHandlers ();
6871 context = app .modelFactory ().fromNull ();
6972 workflowContext = mock (WorkflowContext .class );
7073 workflowInstance = mock (WorkflowInstance .class );
7174 when (workflowContext .context ()).thenReturn (context );
7275 when (workflowContext .definition ()).thenReturn (definition );
7376 when (workflowContext .instanceData ()).thenReturn (workflowInstance );
74- when (workflowInstance .startedAt ()).thenReturn (Instant . now ( ));
77+ when (workflowInstance .startedAt ()).thenReturn (beforeStart . plus ( Duration . ofMillis ( 1 ) ));
7578 when (workflowInstance .context ()).thenReturn (context );
7679 when (workflowInstance .id ()).thenReturn (app .idFactory ().get ());
7780 when (workflowInstance .input ()).thenReturn (app .modelFactory ().from (Map .of ("name" , "Javierito" )));
@@ -127,7 +130,10 @@ void testWorkflowInstance() throws InterruptedException {
127130 assertThat (optional ).isPresent ();
128131 WorkflowPersistenceInstance instance = (WorkflowPersistenceInstance ) optional .orElseThrow ();
129132 assertThat (instance .input ().asMap ().orElseThrow ()).isEqualTo (Map .of ("name" , "Javierito" ));
130- assertThat (instance .startedAt ()).isNotNull ().isBefore (Instant .now ());
133+ assertThat (instance .startedAt ())
134+ .isNotNull ()
135+ .isBefore (Instant .now ())
136+ .isAfterOrEqualTo (beforeStart );
131137
132138 // task retry
133139 WorkflowContext updateWContext = mock (WorkflowContext .class );
0 commit comments