Skip to content

Commit

Permalink
Merge pull request Netflix#1250 from mattrjacobs/fix-more-flaky-unit-…
Browse files Browse the repository at this point in the history
…tests

Larger metric buckets in unit tests to allow for slower CI processing
  • Loading branch information
mattrjacobs authored Jun 21, 2016
2 parents db18a5c + d869bd6 commit 7c9e48b
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ protected Boolean run() {
int v2 = metricsCount.get();

// they should be the same since we were paused
System.out.println("First poll got : " + v1 + ", second got : " + v2);
assertTrue(v2 == v1);

poller.start();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ public void tearDown() {
@Test
public void testEmptyStreamProducesZeros() {
HystrixCommandKey key = HystrixCommandKey.Factory.asKey("CMD-CumulativeCounter-A");
stream = CumulativeCommandEventCounterStream.getInstance(key, 10, 100);
stream = CumulativeCommandEventCounterStream.getInstance(key, 10, 500);
stream.startCachingStreamValuesIfUnstarted();

final CountDownLatch latch = new CountDownLatch(1);
stream.observe().take(10).subscribe(getSubscriber(latch));
stream.observe().take(5).subscribe(getSubscriber(latch));

//no writes

Expand All @@ -98,11 +98,11 @@ public void testEmptyStreamProducesZeros() {
@Test
public void testSingleSuccess() {
HystrixCommandKey key = HystrixCommandKey.Factory.asKey("CMD-CumulativeCounter-B");
stream = CumulativeCommandEventCounterStream.getInstance(key, 10, 100);
stream = CumulativeCommandEventCounterStream.getInstance(key, 10, 500);
stream.startCachingStreamValuesIfUnstarted();

final CountDownLatch latch = new CountDownLatch(1);
stream.observe().take(10).subscribe(getSubscriber(latch));
stream.observe().take(5).subscribe(getSubscriber(latch));

Command cmd = Command.from(groupKey, key, HystrixEventType.SUCCESS, 20);

Expand All @@ -122,11 +122,11 @@ public void testSingleSuccess() {
@Test
public void testSingleFailure() {
HystrixCommandKey key = HystrixCommandKey.Factory.asKey("CMD-CumulativeCounter-C");
stream = CumulativeCommandEventCounterStream.getInstance(key, 10, 100);
stream = CumulativeCommandEventCounterStream.getInstance(key, 10, 500);
stream.startCachingStreamValuesIfUnstarted();

final CountDownLatch latch = new CountDownLatch(1);
stream.observe().take(10).subscribe(getSubscriber(latch));
stream.observe().take(5).subscribe(getSubscriber(latch));

Command cmd = Command.from(groupKey, key, HystrixEventType.FAILURE, 20);

Expand All @@ -147,11 +147,11 @@ public void testSingleFailure() {
@Test
public void testSingleTimeout() {
HystrixCommandKey key = HystrixCommandKey.Factory.asKey("CMD-CumulativeCounter-D");
stream = CumulativeCommandEventCounterStream.getInstance(key, 10, 100);
stream = CumulativeCommandEventCounterStream.getInstance(key, 10, 500);
stream.startCachingStreamValuesIfUnstarted();

final CountDownLatch latch = new CountDownLatch(1);
stream.observe().take(10).subscribe(getSubscriber(latch));
stream.observe().take(5).subscribe(getSubscriber(latch));

Command cmd = Command.from(groupKey, key, HystrixEventType.TIMEOUT);

Expand All @@ -172,11 +172,11 @@ public void testSingleTimeout() {
@Test
public void testSingleBadRequest() {
HystrixCommandKey key = HystrixCommandKey.Factory.asKey("CMD-CumulativeCounter-E");
stream = CumulativeCommandEventCounterStream.getInstance(key, 10, 100);
stream = CumulativeCommandEventCounterStream.getInstance(key, 10, 500);
stream.startCachingStreamValuesIfUnstarted();

final CountDownLatch latch = new CountDownLatch(1);
stream.observe().take(10).subscribe(getSubscriber(latch));
stream.observe().take(5).subscribe(getSubscriber(latch));

Command cmd = Command.from(groupKey, key, HystrixEventType.BAD_REQUEST);

Expand All @@ -197,11 +197,11 @@ public void testSingleBadRequest() {
@Test
public void testRequestFromCache() {
HystrixCommandKey key = HystrixCommandKey.Factory.asKey("CMD-CumulativeCounter-F");
stream = CumulativeCommandEventCounterStream.getInstance(key, 10, 100);
stream = CumulativeCommandEventCounterStream.getInstance(key, 10, 500);
stream.startCachingStreamValuesIfUnstarted();

final CountDownLatch latch = new CountDownLatch(1);
stream.observe().take(10).subscribe(getSubscriber(latch));
stream.observe().take(5).subscribe(getSubscriber(latch));

Command cmd1 = Command.from(groupKey, key, HystrixEventType.SUCCESS, 20);
Command cmd2 = Command.from(groupKey, key, HystrixEventType.RESPONSE_FROM_CACHE);
Expand All @@ -228,11 +228,11 @@ public void testRequestFromCache() {
@Test
public void testShortCircuited() {
HystrixCommandKey key = HystrixCommandKey.Factory.asKey("CMD-CumulativeCounter-G");
stream = CumulativeCommandEventCounterStream.getInstance(key, 10, 100);
stream = CumulativeCommandEventCounterStream.getInstance(key, 10, 500);
stream.startCachingStreamValuesIfUnstarted();

final CountDownLatch latch = new CountDownLatch(1);
stream.observe().take(10).subscribe(getSubscriber(latch));
stream.observe().take(5).subscribe(getSubscriber(latch));

//3 failures in a row will trip circuit. let bucket roll once then submit 2 requests.
//should see 3 FAILUREs and 2 SHORT_CIRCUITs and then 5 FALLBACK_SUCCESSes
Expand All @@ -249,7 +249,7 @@ public void testShortCircuited() {
failure3.observe();

try {
Thread.sleep(100);
Thread.sleep(500);
} catch (InterruptedException ie) {
fail(ie.getMessage());
}
Expand Down Expand Up @@ -277,11 +277,11 @@ public void testShortCircuited() {
@Test
public void testSemaphoreRejected() {
HystrixCommandKey key = HystrixCommandKey.Factory.asKey("CMD-CumulativeCounter-H");
stream = CumulativeCommandEventCounterStream.getInstance(key, 10, 100);
stream = CumulativeCommandEventCounterStream.getInstance(key, 10, 500);
stream.startCachingStreamValuesIfUnstarted();

final CountDownLatch latch = new CountDownLatch(1);
stream.observe().take(10).subscribe(getSubscriber(latch));
stream.observe().take(5).subscribe(getSubscriber(latch));

//10 commands will saturate semaphore when called from different threads.
//submit 2 more requests and they should be SEMAPHORE_REJECTED
Expand All @@ -290,7 +290,7 @@ public void testSemaphoreRejected() {
List<Command> saturators = new ArrayList<Command>();

for (int i = 0; i < 10; i++) {
saturators.add(Command.from(groupKey, key, HystrixEventType.SUCCESS, 200, HystrixCommandProperties.ExecutionIsolationStrategy.SEMAPHORE));
saturators.add(Command.from(groupKey, key, HystrixEventType.SUCCESS, 500, HystrixCommandProperties.ExecutionIsolationStrategy.SEMAPHORE));
}

Command rejected1 = Command.from(groupKey, key, HystrixEventType.SUCCESS, 0, HystrixCommandProperties.ExecutionIsolationStrategy.SEMAPHORE);
Expand Down Expand Up @@ -334,11 +334,11 @@ public void run() {
@Test
public void testThreadPoolRejected() {
HystrixCommandKey key = HystrixCommandKey.Factory.asKey("CMD-CumulativeCounter-I");
stream = CumulativeCommandEventCounterStream.getInstance(key, 10, 100);
stream = CumulativeCommandEventCounterStream.getInstance(key, 10, 500);
stream.startCachingStreamValuesIfUnstarted();

final CountDownLatch latch = new CountDownLatch(1);
stream.observe().take(10).subscribe(getSubscriber(latch));
stream.observe().take(5).subscribe(getSubscriber(latch));

//10 commands will saturate threadpools when called concurrently.
//submit 2 more requests and they should be THREADPOOL_REJECTED
Expand All @@ -347,7 +347,7 @@ public void testThreadPoolRejected() {
List<Command> saturators = new ArrayList<Command>();

for (int i = 0; i < 10; i++) {
saturators.add(Command.from(groupKey, key, HystrixEventType.SUCCESS, 200));
saturators.add(Command.from(groupKey, key, HystrixEventType.SUCCESS, 500));
}

Command rejected1 = Command.from(groupKey, key, HystrixEventType.SUCCESS, 0);
Expand Down Expand Up @@ -386,11 +386,11 @@ public void testThreadPoolRejected() {
@Test
public void testFallbackFailure() {
HystrixCommandKey key = HystrixCommandKey.Factory.asKey("CMD-CumulativeCounter-J");
stream = CumulativeCommandEventCounterStream.getInstance(key, 10, 100);
stream = CumulativeCommandEventCounterStream.getInstance(key, 10, 500);
stream.startCachingStreamValuesIfUnstarted();

final CountDownLatch latch = new CountDownLatch(1);
stream.observe().take(10).subscribe(getSubscriber(latch));
stream.observe().take(5).subscribe(getSubscriber(latch));

Command cmd = Command.from(groupKey, key, HystrixEventType.FAILURE, 20, HystrixEventType.FALLBACK_FAILURE);

Expand All @@ -412,11 +412,11 @@ public void testFallbackFailure() {
@Test
public void testFallbackMissing() {
HystrixCommandKey key = HystrixCommandKey.Factory.asKey("CMD-CumulativeCounter-K");
stream = CumulativeCommandEventCounterStream.getInstance(key, 10, 100);
stream = CumulativeCommandEventCounterStream.getInstance(key, 10, 500);
stream.startCachingStreamValuesIfUnstarted();

final CountDownLatch latch = new CountDownLatch(1);
stream.observe().take(10).subscribe(getSubscriber(latch));
stream.observe().take(5).subscribe(getSubscriber(latch));

Command cmd = Command.from(groupKey, key, HystrixEventType.FAILURE, 20, HystrixEventType.FALLBACK_MISSING);

Expand All @@ -438,11 +438,11 @@ public void testFallbackMissing() {
@Test
public void testFallbackRejection() {
HystrixCommandKey key = HystrixCommandKey.Factory.asKey("CMD-CumulativeCounter-L");
stream = CumulativeCommandEventCounterStream.getInstance(key, 10, 100);
stream = CumulativeCommandEventCounterStream.getInstance(key, 10, 500);
stream.startCachingStreamValuesIfUnstarted();

final CountDownLatch latch = new CountDownLatch(1);
stream.observe().take(10).subscribe(getSubscriber(latch));
stream.observe().take(5).subscribe(getSubscriber(latch));

//fallback semaphore size is 5. So let 5 commands saturate that semaphore, then
//let 2 more commands go to fallback. they should get rejected by the fallback-semaphore
Expand Down Expand Up @@ -485,11 +485,11 @@ public void testFallbackRejection() {
@Test
public void testCancelled() {
HystrixCommandKey key = HystrixCommandKey.Factory.asKey("CMD-CumulativeCounter-M");
stream = CumulativeCommandEventCounterStream.getInstance(key, 10, 100);
stream = CumulativeCommandEventCounterStream.getInstance(key, 10, 500);
stream.startCachingStreamValuesIfUnstarted();

final CountDownLatch latch = new CountDownLatch(1);
stream.observe().take(10).subscribe(getSubscriber(latch));
stream.observe().take(5).subscribe(getSubscriber(latch));

Command toCancel = Command.from(groupKey, key, HystrixEventType.SUCCESS, 500);

Expand Down Expand Up @@ -535,11 +535,11 @@ public void onNext(Integer i) {
@Test
public void testCollapsed() {
HystrixCommandKey key = HystrixCommandKey.Factory.asKey("BatchCommand");
stream = CumulativeCommandEventCounterStream.getInstance(key, 10, 100);
stream = CumulativeCommandEventCounterStream.getInstance(key, 10, 500);
stream.startCachingStreamValuesIfUnstarted();

final CountDownLatch latch = new CountDownLatch(1);
stream.observe().take(10).subscribe(getSubscriber(latch));
stream.observe().take(5).subscribe(getSubscriber(latch));

for (int i = 0; i < 3; i++) {
CommandStreamTest.Collapser.from(i).observe();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ public void tearDown() {
@Test
public void testEmptyStreamProducesZeros() {
HystrixCommandKey key = HystrixCommandKey.Factory.asKey("CMD-Concurrency-A");
stream = RollingCommandMaxConcurrencyStream.getInstance(key, 10, 100);
stream = RollingCommandMaxConcurrencyStream.getInstance(key, 10, 500);
stream.startCachingStreamValuesIfUnstarted();

final CountDownLatch latch = new CountDownLatch(1);
stream.observe().take(10).subscribe(getSubscriber(latch));
stream.observe().take(5).subscribe(getSubscriber(latch));

//no writes

Expand All @@ -99,14 +99,14 @@ public void testEmptyStreamProducesZeros() {
@Test
public void testStartsAndEndsInSameBucketProduceValue() throws InterruptedException {
HystrixCommandKey key = HystrixCommandKey.Factory.asKey("CMD-Concurrency-B");
stream = RollingCommandMaxConcurrencyStream.getInstance(key, 10, 100);
stream = RollingCommandMaxConcurrencyStream.getInstance(key, 10, 500);
stream.startCachingStreamValuesIfUnstarted();

final CountDownLatch latch = new CountDownLatch(1);
stream.observe().take(10).subscribe(getSubscriber(latch));
stream.observe().take(5).subscribe(getSubscriber(latch));

Command cmd1 = Command.from(groupKey, key, HystrixEventType.SUCCESS, 10);
Command cmd2 = Command.from(groupKey, key, HystrixEventType.SUCCESS, 14);
Command cmd1 = Command.from(groupKey, key, HystrixEventType.SUCCESS, 100);
Command cmd2 = Command.from(groupKey, key, HystrixEventType.SUCCESS, 100);

cmd1.observe();
Thread.sleep(1);
Expand All @@ -128,14 +128,14 @@ public void testOneCommandCarriesOverToNextBucket() throws InterruptedException
stream.startCachingStreamValuesIfUnstarted();

final CountDownLatch latch = new CountDownLatch(1);
stream.observe().take(10).subscribe(getSubscriber(latch));
stream.observe().take(5).subscribe(getSubscriber(latch));

Command cmd1 = Command.from(groupKey, key, HystrixEventType.SUCCESS, 160);
Command cmd2 = Command.from(groupKey, key, HystrixEventType.SUCCESS, 10);
Command cmd3 = Command.from(groupKey, key, HystrixEventType.SUCCESS, 15);

cmd1.observe();
Thread.sleep(150); //bucket roll
Thread.sleep(100); //bucket roll
cmd2.observe();
Thread.sleep(1);
cmd3.observe();
Expand Down
Loading

0 comments on commit 7c9e48b

Please sign in to comment.