Skip to content

Commit

Permalink
Fix non-deterministic test
Browse files Browse the repository at this point in the history
- it is relying on scheduling of the collapser timer
- this is an example so specifically should not be refactored to use artifical time
  • Loading branch information
benjchristensen committed May 13, 2013
1 parent 6649237 commit aa3701b
Showing 1 changed file with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,18 @@ public void testCollapser() throws Exception {
assertEquals("ValueForKey: 3", f3.get());
assertEquals("ValueForKey: 4", f4.get());

// assert that the batch command 'GetValueForKey' was in fact
// executed and that it executed only once
assertEquals(1, HystrixRequestLog.getCurrentRequest().getExecutedCommands().size());
HystrixCommand<?> command = HystrixRequestLog.getCurrentRequest().getExecutedCommands().toArray(new HystrixCommand<?>[1])[0];
// assert the command is the one we're expecting
assertEquals("GetValueForKey", command.getCommandKey().name());
// confirm that it was a COLLAPSED command execution
assertTrue(command.getExecutionEvents().contains(HystrixEventType.COLLAPSED));
assertTrue(command.getExecutionEvents().contains(HystrixEventType.SUCCESS));
// assert that the batch command 'GetValueForKey' was in fact executed and that it executed only
// once or twice (due to non-determinism of scheduler since this example uses the real timer)
if (HystrixRequestLog.getCurrentRequest().getExecutedCommands().size() > 2) {
fail("some of the commands should have been collapsed");
}
for (HystrixCommand<?> command : HystrixRequestLog.getCurrentRequest().getExecutedCommands()) {
// assert the command is the one we're expecting
assertEquals("GetValueForKey", command.getCommandKey().name());
// confirm that it was a COLLAPSED command execution
assertTrue(command.getExecutionEvents().contains(HystrixEventType.COLLAPSED));
assertTrue(command.getExecutionEvents().contains(HystrixEventType.SUCCESS));
}
} finally {
context.shutdown();
}
Expand Down

0 comments on commit aa3701b

Please sign in to comment.