@@ -724,21 +724,31 @@ void testTailerIgnoreTouch() throws Exception {
724724
725725 // Write some lines to the file
726726 writeLines (file , "Line one" );
727- final long testDelayMillis = delayMillis * 10 ;
728- TestUtils .sleep (testDelayMillis );
729- List <String > lines = listener .getLines ();
727+ List <String > lines = expectLinesWithLongTimeout (listener , delayMillis , 20 );
730728 assertEquals (1 , lines .size (), "1 line count" );
731729 assertEquals ("Line one" , lines .get (0 ), "1 line 1" );
732730 listener .clear ();
733731
734732 // touch the file
733+ TestUtils .sleepTillNextFullSecond (); // ensure to be within the next second because of posix fs limitation
735734 file .setLastModified (System .currentTimeMillis ());
736- TestUtils .sleep (testDelayMillis );
735+ TestUtils .sleep (delayMillis * 10 );
737736 lines = listener .getLines ();
738737 assertEquals (0 , lines .size (), "nothing should have changed by touching" );
739738 }
740739 }
741740
741+ private List <String > expectLinesWithLongTimeout (final TestTailerListener listener , final long minDelay , int count ) throws Exception {
742+ for (int i = 0 ; i < count ; i ++) {
743+ TestUtils .sleep (minDelay );
744+ final List <String > lines = listener .getLines ();
745+ if (lines .size () > 0 ) {
746+ return lines ;
747+ }
748+ }
749+ throw new RuntimeException ("waiting for TestTailerListener.getLines() timed out after " + (count * minDelay ) + " ms" );
750+ }
751+
742752 @ Test
743753 void testTailerReissueOnTouch () throws Exception {
744754 // Create & start the Tailer
@@ -758,17 +768,15 @@ void testTailerReissueOnTouch() throws Exception {
758768
759769 // Write some lines to the file
760770 writeLines (file , "Line one" );
761- final long testDelayMillis = delayMillis * 10 ;
762- TestUtils .sleep (testDelayMillis );
763- List <String > lines = listener .getLines ();
771+ List <String > lines = expectLinesWithLongTimeout (listener , delayMillis , 50 );
764772 assertEquals (1 , lines .size (), "1 line count" );
765773 assertEquals ("Line one" , lines .get (0 ), "1 line 1" );
766774 listener .clear ();
767775
768776 // touch the file
777+ TestUtils .sleepTillNextFullSecond (); // ensure to be within the next second because of posix fs limitation
769778 file .setLastModified (System .currentTimeMillis ());
770- TestUtils .sleep (testDelayMillis );
771- lines = listener .getLines ();
779+ lines = expectLinesWithLongTimeout (listener , delayMillis , 20 );
772780 assertEquals (1 , lines .size (), "1 line count" );
773781 assertEquals ("Line one" , lines .get (0 ), "1 line 1" );
774782 listener .clear ();
0 commit comments