@@ -354,17 +354,17 @@ public void testChoreServiceConstruction() throws InterruptedException {
354354 public void testFrequencyOfChores () throws InterruptedException {
355355 final int period = 100 ;
356356 // Small delta that acts as time buffer (allowing chores to complete if running slowly)
357- final int delta = 5 ;
357+ final int delta = period / 5 ;
358358 ChoreService service = new ChoreService ("testFrequencyOfChores" );
359359 CountingChore chore = new CountingChore ("countingChore" , period );
360360 try {
361361 service .scheduleChore (chore );
362362
363363 Thread .sleep (10 * period + delta );
364- assertTrue ( chore .getCountOfChoreCalls () == 11 );
364+ assertEquals ( "10 periods have elapsed." , 11 , chore .getCountOfChoreCalls ());
365365
366- Thread .sleep (10 * period );
367- assertTrue ( chore .getCountOfChoreCalls () == 21 );
366+ Thread .sleep (10 * period + delta );
367+ assertEquals ( "20 periods have elapsed." , 21 , chore .getCountOfChoreCalls ());
368368 } finally {
369369 shutdownService (service );
370370 }
@@ -380,14 +380,14 @@ public void shutdownService(ChoreService service) throws InterruptedException {
380380 @ Test
381381 public void testForceTrigger () throws InterruptedException {
382382 final int period = 100 ;
383- final int delta = 10 ;
383+ final int delta = period / 10 ;
384384 ChoreService service = new ChoreService ("testForceTrigger" );
385385 final CountingChore chore = new CountingChore ("countingChore" , period );
386386 try {
387387 service .scheduleChore (chore );
388388 Thread .sleep (10 * period + delta );
389389
390- assertTrue ( chore .getCountOfChoreCalls () == 11 );
390+ assertEquals ( "10 periods have elapsed." , 11 , chore .getCountOfChoreCalls ());
391391
392392 // Force five runs of the chore to occur, sleeping between triggers to ensure the
393393 // chore has time to run
@@ -402,12 +402,14 @@ public void testForceTrigger() throws InterruptedException {
402402 chore .triggerNow ();
403403 Thread .sleep (delta );
404404
405- assertTrue ("" + chore .getCountOfChoreCalls (), chore .getCountOfChoreCalls () == 16 );
405+ assertEquals ("Trigger was called 5 times after 10 periods." , 16 ,
406+ chore .getCountOfChoreCalls ());
406407
407408 Thread .sleep (10 * period + delta );
408409
409410 // Be loosey-goosey. It used to be '26' but it was a big flakey relying on timing.
410- assertTrue ("" + chore .getCountOfChoreCalls (), chore .getCountOfChoreCalls () > 16 );
411+ assertTrue ("Expected at least 16 invocations, instead got " + chore .getCountOfChoreCalls (),
412+ chore .getCountOfChoreCalls () > 16 );
411413 } finally {
412414 shutdownService (service );
413415 }
@@ -419,7 +421,7 @@ public void testCorePoolIncrease() throws InterruptedException {
419421 ChoreService service = new ChoreService ("testCorePoolIncrease" , initialCorePoolSize , false );
420422
421423 try {
422- assertEquals ("Should have a core pool of size: " + initialCorePoolSize , initialCorePoolSize ,
424+ assertEquals ("Setting core pool size gave unexpected results." , initialCorePoolSize ,
423425 service .getCorePoolSize ());
424426
425427 final int slowChorePeriod = 100 ;
@@ -703,7 +705,7 @@ public void testStopperForScheduledChores() throws InterruptedException {
703705 Stoppable stopperForGroup1 = new SampleStopper ();
704706 Stoppable stopperForGroup2 = new SampleStopper ();
705707 final int period = 100 ;
706- final int delta = 10 ;
708+ final int delta = period / 10 ;
707709
708710 try {
709711 ScheduledChore chore1_group1 = new DoNothingChore ("c1g1" , stopperForGroup1 , period );
0 commit comments