You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by bu...@apache.org on 2019/06/22 07:04:14 UTC

[hbase] branch branch-1 updated: HBASE-22615 Make TestChoreService more robust to timing

This is an automated email from the ASF dual-hosted git repository.

busbey pushed a commit to branch branch-1
in repository https://gitbox.apache.org/repos/asf/hbase.git


The following commit(s) were added to refs/heads/branch-1 by this push:
     new 044ffa1  HBASE-22615 Make TestChoreService more robust to timing
044ffa1 is described below

commit 044ffa11560d268a288593facabed3ccb38bedb9
Author: Sean Busbey <bu...@apache.org>
AuthorDate: Sat Jun 22 00:06:39 2019 -0500

    HBASE-22615 Make TestChoreService more robust to timing
    
    * phrase fudge factor "deltas" in terms of the original period
    * increase the delta allowed for chore timing from 5% to 20%
    * improve some assertions
    
    Closes #328
    
    Signed-off-by: Reid Chan <re...@apache.org>
    Signed-off-by: Sakthi <sa...@gmail.com>
    (cherry picked from commit 9aee88e03a376702cad4f5e84acefafad2abf99c)
---
 .../org/apache/hadoop/hbase/TestChoreService.java  | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestChoreService.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestChoreService.java
index aea689f..cabaae8 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestChoreService.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestChoreService.java
@@ -345,17 +345,17 @@ public class TestChoreService {
   public void testFrequencyOfChores() throws InterruptedException {
     final int period = 100;
     // Small delta that acts as time buffer (allowing chores to complete if running slowly)
-    final int delta = 5;
+    final int delta = period/5;
     ChoreService service = new ChoreService("testFrequencyOfChores");
     CountingChore chore = new CountingChore("countingChore", period);
     try {
       service.scheduleChore(chore);
 
       Thread.sleep(10 * period + delta);
-      assertTrue(chore.getCountOfChoreCalls() == 11);
+      assertEquals("10 periods have elapsed.", 11, chore.getCountOfChoreCalls());
 
-      Thread.sleep(10 * period);
-      assertTrue(chore.getCountOfChoreCalls() == 21);
+      Thread.sleep(10 * period + delta);
+      assertEquals("20 periods have elapsed.", 21, chore.getCountOfChoreCalls());
     } finally {
       shutdownService(service);
     }
@@ -371,14 +371,14 @@ public class TestChoreService {
   @Test (timeout=20000)
   public void testForceTrigger() throws InterruptedException {
     final int period = 100;
-    final int delta = 10;
+    final int delta = period/10;
     ChoreService service = new ChoreService("testForceTrigger");
     final CountingChore chore = new CountingChore("countingChore", period);
     try {
       service.scheduleChore(chore);
       Thread.sleep(10 * period + delta);
 
-      assertTrue(chore.getCountOfChoreCalls() == 11);
+      assertEquals("10 periods have elapsed.", 11, chore.getCountOfChoreCalls());
 
       // Force five runs of the chore to occur, sleeping between triggers to ensure the
       // chore has time to run
@@ -393,12 +393,14 @@ public class TestChoreService {
       chore.triggerNow();
       Thread.sleep(delta);
 
-      assertTrue("" + chore.getCountOfChoreCalls(), chore.getCountOfChoreCalls() == 16);
+      assertEquals("Trigger was called 5 times after 10 periods.", 16,
+          chore.getCountOfChoreCalls());
 
       Thread.sleep(10 * period + delta);
 
       // Be loosey-goosey. It used to be '26' but it was a big flakey relying on timing.
-      assertTrue("" + chore.getCountOfChoreCalls(), chore.getCountOfChoreCalls() > 16);
+      assertTrue("Expected at least 16 invocations, instead got " + chore.getCountOfChoreCalls(),
+          chore.getCountOfChoreCalls() > 16);
     } finally {
       shutdownService(service);
     }
@@ -410,7 +412,7 @@ public class TestChoreService {
     ChoreService service = new ChoreService("testCorePoolIncrease", initialCorePoolSize, false);
 
     try {
-      assertEquals("Should have a core pool of size: " + initialCorePoolSize, initialCorePoolSize,
+      assertEquals("Setting core pool size gave unexpected results.", initialCorePoolSize,
         service.getCorePoolSize());
 
       final int slowChorePeriod = 100;
@@ -694,7 +696,7 @@ public class TestChoreService {
     Stoppable stopperForGroup1 = new SampleStopper();
     Stoppable stopperForGroup2 = new SampleStopper();
     final int period = 100;
-    final int delta = 10;
+    final int delta = period/10;
 
     try {
       ScheduledChore chore1_group1 = new DoNothingChore("c1g1", stopperForGroup1, period);