Skip to content

Commit

Permalink
Merge pull request Netflix#580 from mattrjacobs/add-nonblocking-queue…
Browse files Browse the repository at this point in the history
…-test

Add unit test that demonstrates non-blocking timeout for HystrixCommand.queue()
  • Loading branch information
mattrjacobs committed Jan 28, 2015
2 parents ecbc9e1 + aa6687c commit 05ce2a1
Showing 1 changed file with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3486,6 +3486,30 @@ public void onNext(Boolean args) {
assertEquals(0, circuitBreaker.metrics.getRollingCount(HystrixRollingNumberEvent.BAD_REQUEST));
}

@Test
public void testNonBlockingCommandQueueFiresTimeout() { //see https://github.com/Netflix/Hystrix/issues/514
final TestHystrixCommand<Boolean> cmd = new TestCommandWithTimeout(50, TestCommandWithTimeout.FALLBACK_SUCCESS);

new Thread() {
@Override
public void run() {
cmd.queue();
}
}.start();

try {
Thread.sleep(200);
//timeout should occur in 50ms, and underlying thread should run for 500ms
//therefore, after 200ms, the command should have finished with a fallback on timeout
} catch (InterruptedException ie) {
throw new RuntimeException(ie);
}

assertTrue(cmd.isExecutionComplete());
assertTrue(cmd.isResponseTimedOut());
}


/**
* Run the command in multiple modes and check that the hook assertions hold in each and that the command succeeds
* @param ctor {@link com.netflix.hystrix.HystrixCommandTest.TestHystrixCommand} constructor
Expand Down

0 comments on commit 05ce2a1

Please sign in to comment.