3030import static engineering .swat .watch .WatchEvent .Kind .DELETED ;
3131import static engineering .swat .watch .WatchEvent .Kind .MODIFIED ;
3232import static engineering .swat .watch .WatchEvent .Kind .OVERFLOW ;
33- import static org .awaitility .Awaitility .await ;
33+ import static engineering .swat .watch .util .WaitFor .await ;
34+ import static org .junit .jupiter .api .Assertions .assertTrue ;
3435
3536import java .io .IOException ;
3637import java .nio .file .Files ;
3738import java .nio .file .attribute .FileTime ;
3839import java .time .Instant ;
3940import java .util .concurrent .atomic .AtomicBoolean ;
41+ import java .util .function .BooleanSupplier ;
4042
4143import org .awaitility .Awaitility ;
4244import org .junit .jupiter .api .AfterEach ;
4547import org .junit .jupiter .api .Test ;
4648
4749import engineering .swat .watch .impl .EventHandlingWatch ;
50+ import engineering .swat .watch .util .WaitFor ;
4851
4952class SingleFileTests {
5053 private TestDirectory testDir ;
@@ -63,7 +66,7 @@ void cleanup() {
6366
6467 @ BeforeAll
6568 static void setupEverything () {
66- Awaitility .setDefaultTimeout (TestHelper .NORMAL_WAIT );
69+ WaitFor .setDefaultTimeout (TestHelper .NORMAL_WAIT );
6770 }
6871
6972 @ Test
@@ -86,12 +89,11 @@ void singleFileShouldNotTriggerOnOtherFilesInSameDir() throws IOException, Inter
8689 Files .writeString (f , "Hello" );
8790 }
8891 }
89- Thread .sleep (TestHelper .SHORT_WAIT .toMillis ());
92+ Thread .sleep (TestHelper .SMALL_WAIT .toMillis ());
9093 Files .writeString (target , "Hello world" );
9194 await ("Single file does trigger" )
92- .pollDelay (TestHelper .NORMAL_WAIT .minusMillis (10 ))
93- .failFast ("No others should be notified" , others ::get )
94- .untilTrue (seen );
95+ .failFast ("Other files should not trigger" , others ::get )
96+ .until (seen );
9597 }
9698 }
9799
@@ -115,41 +117,50 @@ void singleFileThatMonitorsOnlyADirectory() throws IOException, InterruptedExcep
115117 Files .writeString (f , "Hello" );
116118 }
117119 }
118- Thread .sleep (TestHelper .SHORT_WAIT .toMillis ());
120+ Thread .sleep (TestHelper .SMALL_WAIT .toMillis ());
119121 Files .setLastModifiedTime (target , FileTime .from (Instant .now ()));
120122 await ("Single directory does trigger" )
121- .pollDelay (TestHelper .NORMAL_WAIT .minusMillis (10 ))
122123 .failFast ("No others should be notified" , others ::get )
123- .untilTrue (seen );
124+ .until (seen );
124125 }
125126 }
126127
127128 @ Test
128129 void noRescanOnOverflow () throws IOException , InterruptedException {
129130 var bookkeeper = new TestHelper .Bookkeeper ();
130131 try (var watch = startWatchAndTriggerOverflow (Approximation .NONE , bookkeeper )) {
131- Thread .sleep (TestHelper .SHORT_WAIT .toMillis ());
132+ // Thread.sleep(TestHelper.SMALL_WAIT .toMillis());
132133
133- await ("Overflow shouldn't trigger created, modified, or deleted events: " + bookkeeper )
134- .until (() -> bookkeeper .events ().kind (CREATED , MODIFIED , DELETED ).none ());
135134 await ("Overflow should be visible to user-defined event handler" )
136135 .until (() -> bookkeeper .events ().kind (OVERFLOW ).any ());
136+ await ("Overflow shouldn't trigger created, modified, or deleted events: " + bookkeeper )
137+ .time (TestHelper .SMALL_WAIT )
138+ .holds (() -> bookkeeper .events ().kind (CREATED , MODIFIED , DELETED ).none ());
137139 }
138140 }
139141
140142 @ Test
141143 void memorylessRescanOnOverflow () throws IOException , InterruptedException {
142144 var bookkeeper = new TestHelper .Bookkeeper ();
143145 try (var watch = startWatchAndTriggerOverflow (Approximation .ALL , bookkeeper )) {
144- Thread .sleep (TestHelper .SHORT_WAIT .toMillis ());
146+ // Thread.sleep(TestHelper.SMALL_WAIT .toMillis());
145147
146148 var path = watch .getPath ();
147149 await ("Overflow should trigger created event for `" + path + "`" )
148150 .until (() -> bookkeeper .events ().kind (CREATED ).rootPath (path ).any ());
149- await ("Overflow shouldn't trigger created events for other files" )
150- .until (() -> bookkeeper .events ().kind (CREATED ).rootPathNot (path ).none ());
151- await ("Overflow shouldn't trigger modified or deleted events" )
152- .until (() -> bookkeeper .events ().kind (MODIFIED , DELETED ).none ());
151+ await ("No extra events" )
152+ .time (TestHelper .SMALL_WAIT )
153+ .holds (() -> {
154+ assertTrue (
155+ bookkeeper .events ().kind (CREATED ).rootPathNot (path ).none (),
156+ "Overflow shouldn't trigger created events for other files"
157+ );
158+ assertTrue (
159+ bookkeeper .events ().kind (MODIFIED , DELETED ).none ()
160+ ,"Overflow shouldn't trigger modified or deleted events"
161+ );
162+ return true ;
163+ });
153164 await ("Overflow should be visible to user-defined event handler" )
154165 .until (() -> bookkeeper .events ().kind (OVERFLOW ).any ());
155166 }
0 commit comments