@@ -354,17 +354,17 @@ public void testChoreServiceConstruction() throws InterruptedException {
354
354
public void testFrequencyOfChores () throws InterruptedException {
355
355
final int period = 100 ;
356
356
// 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 ;
358
358
ChoreService service = new ChoreService ("testFrequencyOfChores" );
359
359
CountingChore chore = new CountingChore ("countingChore" , period );
360
360
try {
361
361
service .scheduleChore (chore );
362
362
363
363
Thread .sleep (10 * period + delta );
364
- assertTrue ( chore .getCountOfChoreCalls () == 11 );
364
+ assertEquals ( "10 periods have elapsed." , 11 , chore .getCountOfChoreCalls ());
365
365
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 ());
368
368
} finally {
369
369
shutdownService (service );
370
370
}
@@ -380,14 +380,14 @@ public void shutdownService(ChoreService service) throws InterruptedException {
380
380
@ Test
381
381
public void testForceTrigger () throws InterruptedException {
382
382
final int period = 100 ;
383
- final int delta = 10 ;
383
+ final int delta = period / 10 ;
384
384
ChoreService service = new ChoreService ("testForceTrigger" );
385
385
final CountingChore chore = new CountingChore ("countingChore" , period );
386
386
try {
387
387
service .scheduleChore (chore );
388
388
Thread .sleep (10 * period + delta );
389
389
390
- assertTrue ( chore .getCountOfChoreCalls () == 11 );
390
+ assertEquals ( "10 periods have elapsed." , 11 , chore .getCountOfChoreCalls ());
391
391
392
392
// Force five runs of the chore to occur, sleeping between triggers to ensure the
393
393
// chore has time to run
@@ -402,12 +402,14 @@ public void testForceTrigger() throws InterruptedException {
402
402
chore .triggerNow ();
403
403
Thread .sleep (delta );
404
404
405
- assertTrue ("" + chore .getCountOfChoreCalls (), chore .getCountOfChoreCalls () == 16 );
405
+ assertEquals ("Trigger was called 5 times after 10 periods." , 16 ,
406
+ chore .getCountOfChoreCalls ());
406
407
407
408
Thread .sleep (10 * period + delta );
408
409
409
410
// 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 );
411
413
} finally {
412
414
shutdownService (service );
413
415
}
@@ -419,7 +421,7 @@ public void testCorePoolIncrease() throws InterruptedException {
419
421
ChoreService service = new ChoreService ("testCorePoolIncrease" , initialCorePoolSize , false );
420
422
421
423
try {
422
- assertEquals ("Should have a core pool of size: " + initialCorePoolSize , initialCorePoolSize ,
424
+ assertEquals ("Setting core pool size gave unexpected results." , initialCorePoolSize ,
423
425
service .getCorePoolSize ());
424
426
425
427
final int slowChorePeriod = 100 ;
@@ -703,7 +705,7 @@ public void testStopperForScheduledChores() throws InterruptedException {
703
705
Stoppable stopperForGroup1 = new SampleStopper ();
704
706
Stoppable stopperForGroup2 = new SampleStopper ();
705
707
final int period = 100 ;
706
- final int delta = 10 ;
708
+ final int delta = period / 10 ;
707
709
708
710
try {
709
711
ScheduledChore chore1_group1 = new DoNothingChore ("c1g1" , stopperForGroup1 , period );
0 commit comments