Skip to content

Commit

Permalink
[TESTS] Be less strict about breaker child limit
Browse files Browse the repository at this point in the history
Failing a parent breaker check is eventually consistent, so the test
could fail the parent limit, throw an exception, and before being
adjusted back down, increment more and throw a circuit breaking
exception on the child. This increases the child's limit, to ensure
we're only testing the parent limit.

It adds an additional assert to ensure that the breaker total is
correctly re-adjusted when the parent breaker has been tripped.
  • Loading branch information
dakrone committed Sep 30, 2014
1 parent 4e3f3e7 commit c86fdec
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ public void testThreadedUpdatesToChildBreakerWithParentLimit() throws Exception
final int NUM_THREADS = scaledRandomIntBetween(3, 15);
final int BYTES_PER_THREAD = scaledRandomIntBetween(500, 4500);
final int parentLimit = (BYTES_PER_THREAD * NUM_THREADS) - 2;
final int childLimit = parentLimit + 10;
final Thread[] threads = new Thread[NUM_THREADS];
final AtomicInteger tripped = new AtomicInteger(0);
final AtomicReference<Throwable> lastException = new AtomicReference<>(null);
Expand All @@ -167,7 +168,7 @@ public void checkParentLimit(String label) throws CircuitBreakingException {
}
}
};
final BreakerSettings settings = new BreakerSettings(CircuitBreaker.Name.REQUEST, parentLimit + 1, 1.0);
final BreakerSettings settings = new BreakerSettings(CircuitBreaker.Name.REQUEST, childLimit, 1.0);
final ChildMemoryCircuitBreaker breaker = new ChildMemoryCircuitBreaker(settings, logger,
(HierarchyCircuitBreakerService)service, CircuitBreaker.Name.REQUEST);
breakerRef.set(breaker);
Expand All @@ -193,7 +194,7 @@ public void run() {
}

logger.info("--> NUM_THREADS: [{}], BYTES_PER_THREAD: [{}], TOTAL_BYTES: [{}], PARENT_LIMIT: [{}], CHILD_LIMIT: [{}]",
NUM_THREADS, BYTES_PER_THREAD, (BYTES_PER_THREAD * NUM_THREADS), parentLimit, parentLimit + 1);
NUM_THREADS, BYTES_PER_THREAD, (BYTES_PER_THREAD * NUM_THREADS), parentLimit, childLimit);

logger.info("--> starting threads...");
for (Thread t : threads) {
Expand All @@ -211,6 +212,8 @@ public void run() {
breaker.getUsed(), equalTo((long)parentLimit));
assertThat("parent breaker was tripped exactly twice", parentTripped.get(), equalTo(2));
assertThat("total breaker was tripped exactly twice", tripped.get(), equalTo(2));
assertThat("breaker total is expected value: " + parentLimit, breaker.getUsed(), equalTo((long)
parentLimit));
}

@Test
Expand Down

0 comments on commit c86fdec

Please sign in to comment.