From aa6687cb513ec716877d1c65c77c6278bd769312 Mon Sep 17 00:00:00 2001 From: Matt Jacobs Date: Tue, 27 Jan 2015 21:29:18 -0800 Subject: [PATCH] Add unit test that demonstrates non-blocking timeout for HystrixCommand.queue() --- .../netflix/hystrix/HystrixCommandTest.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/hystrix-core/src/test/java/com/netflix/hystrix/HystrixCommandTest.java b/hystrix-core/src/test/java/com/netflix/hystrix/HystrixCommandTest.java index 0aab3b36a..fd293c398 100644 --- a/hystrix-core/src/test/java/com/netflix/hystrix/HystrixCommandTest.java +++ b/hystrix-core/src/test/java/com/netflix/hystrix/HystrixCommandTest.java @@ -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 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