package org.skyscreamer.nevado.jms.util;

import org.junit.Assert;
import org.junit.Test;

/**
 * Tests the BackoffSleeper.
 *
 * @author Carter Page <carter@skyscreamer.org>
 */
public class BackoffSleeperTest {
    @Test
    public void testBackoffSleeper() throws InterruptedException {
        BackoffSleeper sleeper = new BackoffSleeper(10, 100, 2.0);
        long now = System.currentTimeMillis();
        sleeper.sleep();
        Assert.assertEquals(now + 10, System.currentTimeMillis(), 10);
        sleeper.sleep();
        Assert.assertEquals(now + 30, System.currentTimeMillis(), 10);
        sleeper.sleep();
        Assert.assertEquals(now + 70, System.currentTimeMillis(), 10);
        sleeper.sleep();
        Assert.assertEquals(now + 150, System.currentTimeMillis(), 10);
        sleeper.sleep();
        Assert.assertEquals(now + 250, System.currentTimeMillis(), 10);
        sleeper.reset();
        Assert.assertEquals(now + 250, System.currentTimeMillis(), 10);
        sleeper.sleep();
        Assert.assertEquals(now + 260, System.currentTimeMillis(), 10);
    }
}

@@ -206,16 +206,154 @@
 rTest %7B%0A
+    // Cloudbees needs coarse resolution because their boxes have heavy contention%0A    public static final int ACCEPTABLE_DELTA_MS = 50;%0A%0A
     @Tes
@@ -477,14 +477,14 @@
 per(
-10, 10
+50, 23
 0, 2
@@ -594,17 +594,17 @@
 s(now + 
-1
+5
 0, Syste
@@ -618,34 +618,51 @@
 ntTimeMillis(), 
-10
+ACCEPTABLE_DELTA_MS
 );%0A        sleep
@@ -707,17 +707,18 @@
 s(now + 
-3
+15
 0, Syste
@@ -732,34 +732,51 @@
 ntTimeMillis(), 
-10
+ACCEPTABLE_DELTA_MS
 );%0A        sleep
@@ -825,9 +825,10 @@
 w + 
-7
+35
 0, S
@@ -846,34 +846,51 @@
 ntTimeMillis(), 
-10
+ACCEPTABLE_DELTA_MS
 );%0A        sleep
@@ -927,34 +927,34 @@
 ertEquals(now + 
-1
 5
+8
 0, System.curren
@@ -960,34 +960,51 @@
 ntTimeMillis(), 
-10
+ACCEPTABLE_DELTA_MS
 );%0A        sleep
@@ -1041,34 +1041,34 @@
 ertEquals(now + 
-25
+81
 0, System.curren
@@ -1074,34 +1074,51 @@
 ntTimeMillis(), 
-10
+ACCEPTABLE_DELTA_MS
 );%0A        sleep
@@ -1167,10 +1167,10 @@
 w + 
-25
+81
 0, S
@@ -1192,26 +1192,43 @@
 meMillis(), 
-10
+ACCEPTABLE_DELTA_MS
 );%0A        s
@@ -1277,17 +1277,17 @@
 s(now + 
-2
+8
 60, Syst
@@ -1310,18 +1310,35 @@
 llis(), 
-10
+ACCEPTABLE_DELTA_MS
 );%0A    %7D

Make timer test more coarse to avoid race conditions with Cloudbees