2626 */
2727package engineering .swat .watch ;
2828
29- import static org . awaitility . Awaitility .await ;
29+ import static engineering . swat . watch . util . WaitFor .await ;
3030import static org .junit .jupiter .api .Assertions .assertTrue ;
3131import static org .junit .jupiter .api .Assertions .fail ;
3232
4545import java .util .concurrent .Semaphore ;
4646import java .util .concurrent .TimeUnit ;
4747import java .util .concurrent .atomic .AtomicInteger ;
48- import java .util .function .Predicate ;
4948import java .util .stream .Stream ;
5049
5150import org .apache .logging .log4j .LogManager ;
5251import org .apache .logging .log4j .Logger ;
53- import org .awaitility .Awaitility ;
5452import org .junit .jupiter .api .AfterEach ;
5553import org .junit .jupiter .api .BeforeAll ;
5654import org .junit .jupiter .api .BeforeEach ;
6058import org .junit .jupiter .params .provider .EnumSource ;
6159import org .junit .jupiter .params .provider .MethodSource ;
6260
61+ import engineering .swat .watch .util .WaitFor ;
62+
6363class TortureTests {
6464
6565 private final Logger logger = LogManager .getLogger ();
@@ -68,7 +68,7 @@ class TortureTests {
6868
6969 @ BeforeAll
7070 static void setupEverything () {
71- Awaitility .setDefaultTimeout (TestHelper .LONG_WAIT . getSeconds (), TimeUnit . SECONDS );
71+ WaitFor .setDefaultTimeout (TestHelper .LONG_WAIT );
7272 }
7373
7474 @ BeforeEach
@@ -181,13 +181,13 @@ void pressureOnFSShouldNotMissNewFilesAnything(Approximation whichFiles) throws
181181 logger .info ("Starting {} jobs" , THREADS );
182182 io .start ();
183183 // now we generate a whole bunch of events
184- Thread .sleep (TestHelper .NORMAL_WAIT .toMillis ());
184+ Thread .sleep (Math . min ( TestHelper .NORMAL_WAIT .toMillis (), Duration . ofSeconds ( 30 ). toMillis () ));
185185 logger .info ("Stopping jobs" );
186186 pathsWritten = io .stop ();
187187 logger .info ("Generated: {} files" , pathsWritten .size ());
188188
189189 await ("After a while we should have seen all the create events" )
190- .timeout (TestHelper .LONG_WAIT .multipliedBy (50 ))
190+ .time (TestHelper .LONG_WAIT .multipliedBy (50 ))
191191 .pollInterval (Duration .ofMillis (500 ))
192192 .until (() -> seenCreates .containsAll (pathsWritten ));
193193 }
@@ -254,10 +254,10 @@ void manyRegistrationsForSamePath() throws InterruptedException, IOException {
254254 Files .writeString (target , "Hello World" );
255255 var expected = Collections .singleton (target );
256256 await ("We should see only one event" )
257- .failFast (() -> !exceptions .isEmpty ())
258- .timeout (TestHelper .LONG_WAIT )
257+ .failFast (() -> "There was an exception: " + exceptions , () -> !exceptions .isEmpty ())
258+ .time (TestHelper .NORMAL_WAIT )
259259 .pollInterval (Duration .ofMillis (10 ))
260- .until (() -> seen , expected :: equals );
260+ .untilEquals (() -> seen , expected );
261261 if (!exceptions .isEmpty ()) {
262262 fail (exceptions .pop ());
263263 }
@@ -269,7 +269,7 @@ void manyRegistrationsForSamePath() throws InterruptedException, IOException {
269269
270270 static Stream <Approximation > manyRegisterAndUnregisterSameTimeSource () {
271271 Approximation [] values = { Approximation .ALL , Approximation .DIFF };
272- return TestHelper .streamOf (values , 5 );
272+ return TestHelper .streamOf (values , 3 );
273273 }
274274
275275 @ ParameterizedTest
@@ -328,9 +328,9 @@ void manyRegisterAndUnregisterSameTime(Approximation whichFiles) throws Interrup
328328 assertTrue (seen .isEmpty (), "No events should have been sent" );
329329 Files .writeString (target , "Hello World" );
330330 await ("We should see only exactly the " + amountOfWatchersActive + " events we expect" )
331- .failFast (() -> ! exceptions . isEmpty () )
332- .pollDelay ( TestHelper . NORMAL_WAIT . minusMillis ( 100 ))
333- .until (seen ::size , Predicate . isEqual ( amountOfWatchersActive ) )
331+ .time ( TestHelper . SHORT_WAIT )
332+ .failFast (() -> "There was an exception: " + exceptions , () -> ! exceptions . isEmpty ( ))
333+ .delayedHoldsEquals (seen ::size , amountOfWatchersActive )
334334 ;
335335 if (!exceptions .isEmpty ()) {
336336 fail (exceptions .pop ());
0 commit comments