Skip to content

Commit

Permalink
Merge pull request Netflix#1138 from mattrjacobs/deflake-command-unit…
Browse files Browse the repository at this point in the history
…-tests

Made errors in hook unit tests easier to debug
  • Loading branch information
mattrjacobs committed Mar 11, 2016
2 parents 071fcee + 85d2aa2 commit f98a027
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -925,7 +925,6 @@ public void testShortCircuitFallbackCounter() {

assertCommandExecutionEvents(command1, HystrixEventType.SHORT_CIRCUITED, HystrixEventType.FALLBACK_EMIT, HystrixEventType.FALLBACK_SUCCESS);
assertCommandExecutionEvents(command2, HystrixEventType.SHORT_CIRCUITED, HystrixEventType.FALLBACK_EMIT, HystrixEventType.FALLBACK_SUCCESS);
assertEquals(0, circuitBreaker.metrics.getCurrentConcurrentExecutionCount());
assertSaneHystrixRequestLog(2);
}

Expand Down Expand Up @@ -1182,7 +1181,6 @@ public void onNext(Boolean b) {
}
}
assertEquals("expected some of shared semaphore commands to get rejected", sharedSemaphore.numberOfPermits.get().longValue(), numSemaphoreRejected);
assertEquals(0, circuitBreaker.metrics.getCurrentConcurrentExecutionCount());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,30 +48,40 @@ public boolean fallbackEventsMatch(int numOnNext, int numOnError, int numOnCompl
}

private boolean eventsMatch(List<Notification<?>> l, int numOnNext, int numOnError, int numOnCompleted) {
if (numOnNext + numOnError + numOnCompleted != l.size()) {
System.err.println("Events : " + l.size() + " don't add up to the events you asked to verify");
return false;
}
boolean matchSoFar = true;
boolean matchFailed = false;
int actualOnNext = 0;
int actualOnError = 0;
int actualOnCompleted = 0;

for (int n = 0; n < numOnNext; n++) {
Notification<?> current = l.get(n);
if (!current.isOnNext()) {
matchSoFar = false;
matchFailed = true;
} else {
actualOnNext++;
}
}
for (int e = numOnNext; e < numOnNext + numOnError; e++) {
Notification<?> current = l.get(e);
if (!current.isOnError()) {
matchSoFar = false;
matchFailed = true;
} else {
actualOnError++;
}
}
for (int c = numOnNext + numOnError; c < numOnNext + numOnError + numOnCompleted; c++) {
Notification<?> current = l.get(c);
if (!current.isOnCompleted()) {
matchSoFar = false;
matchFailed = true;
} else {
actualOnCompleted++;
}
}
return matchSoFar;
if (matchFailed) {
System.out.println("Expected : " + numOnNext + " OnNexts, " + numOnError + " OnErrors, and " + numOnCompleted);
System.out.println("Actual : " + actualOnNext + " OnNexts, " + actualOnError + " OnErrors, and " + actualOnCompleted);
}
return !matchFailed;
}

public Throwable getCommandException() {
Expand Down

0 comments on commit f98a027

Please sign in to comment.