forked from Netflix/Hystrix
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request Netflix#256 from benjchristensen/timeout-race-cond…
…ition Fix Race Condition on Timeout
- Loading branch information
Showing
2 changed files
with
135 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
hystrix-core/src/test/java/com/netflix/hystrix/HystrixCommandTimeoutConcurrencyTesting.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package com.netflix.hystrix; | ||
import org.junit.Test; | ||
|
||
import com.netflix.hystrix.strategy.concurrency.HystrixRequestContext; | ||
|
||
public class HystrixCommandTimeoutConcurrencyTesting { | ||
|
||
@Test | ||
public void testTimeoutRace() { | ||
for (int i = 0; i < 2000; i++) { | ||
String a = null; | ||
String b = null; | ||
try { | ||
HystrixRequestContext.initializeContext(); | ||
a = new TestCommand().execute(); | ||
b = new TestCommand().execute(); | ||
if (a == null || b == null) { | ||
System.err.println("Received NULL!"); | ||
throw new RuntimeException("Received NULL"); | ||
} | ||
|
||
for (HystrixExecutableInfo<?> hi : HystrixRequestLog.getCurrentRequest().getAllExecutedCommands()) { | ||
if (hi.isResponseTimedOut() && hi.getExecutionEvents().size() == 1) { | ||
System.err.println("Missing fallback status!"); | ||
throw new RuntimeException("Missing fallback status on timeout."); | ||
} | ||
} | ||
|
||
} catch (Exception e) { | ||
System.err.println("Error: " + e.getMessage()); | ||
e.printStackTrace(); | ||
throw new RuntimeException(e); | ||
} finally { | ||
System.out.println(a + " " + b + " ==> " + HystrixRequestLog.getCurrentRequest().getExecutedCommandsAsString()); | ||
HystrixRequestContext.getContextForCurrentThread().shutdown(); | ||
} | ||
} | ||
|
||
Hystrix.reset(); | ||
} | ||
|
||
public static class TestCommand extends HystrixCommand<String> { | ||
|
||
protected TestCommand() { | ||
super(Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey("testTimeoutConcurrency")) | ||
.andCommandKey(HystrixCommandKey.Factory.asKey("testTimeoutConcurrencyCommand")) | ||
.andCommandPropertiesDefaults(HystrixCommandProperties.Setter() | ||
.withExecutionIsolationThreadTimeoutInMilliseconds(1))); | ||
} | ||
|
||
@Override | ||
protected String run() throws Exception { | ||
// throw new RuntimeException("test"); | ||
// Thread.sleep(5); | ||
return "hello"; | ||
} | ||
|
||
@Override | ||
protected String getFallback() { | ||
return "failed"; | ||
} | ||
|
||
} | ||
} |