2929import java .io .IOException ;
3030import java .nio .file .Files ;
3131import java .nio .file .Path ;
32+ import java .time .Duration ;
3233import java .util .Collection ;
3334import java .util .Map ;
3435import java .util .concurrent .ExecutorService ;
3536import java .util .concurrent .Executors ;
36- import java .util .concurrent .TimeUnit ;
3737import java .util .stream .Stream ;
38+ import org .awaitility .Awaitility ;
3839import org .junit .jupiter .api .Test ;
3940
4041public class MvStorePersistenceTest {
@@ -53,20 +54,20 @@ void testSimpleRun() throws Exception {
5354 WorkflowDefinition definition =
5455 application .workflowDefinition (
5556 readWorkflowFromClasspath ("workflows-samples/simple-expression.yaml" ));
56- assertNoInstance (handlers , definition );
57+ assertThat ( assertNoInstance (handlers , definition )). isTrue ( );
5758 definition .instance (Map .of ()).start ().join ();
58- service . shutdown ();
59- service . awaitTermination ( 500 , TimeUnit . MILLISECONDS );
60- assertNoInstance (handlers , definition );
59+ Awaitility . await ()
60+ . atMost ( Duration . ofSeconds ( 1 ))
61+ . until (() -> assertNoInstance (handlers , definition ) );
6162 } finally {
6263 Files .delete (Path .of (dbName ));
6364 }
6465 }
6566
66- private void assertNoInstance (
67+ private boolean assertNoInstance (
6768 PersistenceInstanceHandlers handlers , WorkflowDefinition definition ) {
6869 try (Stream <WorkflowInstance > stream = handlers .reader ().scanAll (definition )) {
69- assertThat ( stream .count ()). isEqualTo ( 0 ) ;
70+ return stream .count () == 0 ;
7071 }
7172 }
7273
0 commit comments