From 1d35782ea403d4b1ff27ee91a92b147548117f2b Mon Sep 17 00:00:00 2001 From: Matt Jacobs Date: Thu, 15 Jan 2015 22:18:17 -0800 Subject: [PATCH] Unit test demonstrating that a timeout does not fire properly when command.queue() is called with no blocking performed on the resulting Future --- .../com/netflix/hystrix/HystrixCommand.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/hystrix-core/src/main/java/com/netflix/hystrix/HystrixCommand.java b/hystrix-core/src/main/java/com/netflix/hystrix/HystrixCommand.java index 6b6068660..f838ffdbb 100755 --- a/hystrix-core/src/main/java/com/netflix/hystrix/HystrixCommand.java +++ b/hystrix-core/src/main/java/com/netflix/hystrix/HystrixCommand.java @@ -3403,6 +3403,29 @@ public void testShortCircuitFallbackCounter() { assertEquals(2, HystrixRequestLog.getCurrentRequest().getExecutedCommands().size()); } + @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()); + } + /** * Test when a command fails to get queued up in the threadpool where the command didn't implement getFallback. *