Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed thread leak in timeout implementation. Closes #639

  • Loading branch information...
commit b67c24c666a1e37ebc3d55acb67d5118870e8ffc 1 parent 5ca341d
@aslakhellesoy aslakhellesoy authored
Showing with 22 additions and 25 deletions.
  1. +1 −0  History.md
  2. +21 −25 core/src/test/java/cucumber/runtime/TimeoutTest.java
View
1  History.md
@@ -1,5 +1,6 @@
## [1-1-6-SNAPSHOT (Git master)](https://github.com/cucumber/cucumber-jvm/compare/v1.1.5...master)
+* [Core] Fixed thread leak in timeout implementation. ([#639](https://github.com/cucumber/cucumber-jvm/issues/639), [#640](https://github.com/cucumber/cucumber-jvm/pull/640), Nikolay Volnov)
* [TestNG] Allow TestNG Cucumber runner to use composition instead of inheritance. ([#622](https://github.com/cucumber/cucumber-jvm/pull/622) Marty Kube)
* [Core] New Snippet text. ([#618](https://github.com/cucumber/cucumber-jvm/issues/618) Jeff Nyman, Matt Wynne, Aslak Hellesøy)
* [Android] Add command line option support for Android ([#597](https://github.com/cucumber/cucumber-jvm/pull/597), Frieder Bluemle)
View
46 core/src/test/java/cucumber/runtime/TimeoutTest.java
@@ -5,9 +5,7 @@
import java.util.concurrent.TimeoutException;
import static java.lang.Thread.sleep;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.junit.Assert.*;
public class TimeoutTest {
@Test
@@ -34,28 +32,6 @@ public String call() throws Throwable {
fail();
}
- @Test
- public void no_thread_leak() throws Throwable{
-
- final long startNumberOfThreads = Thread.getAllStackTraces().size();
-
- for(int i = 0; i < 1000; i++){
- Timeout.timeout(new Timeout.Callback<String>() {
- @Override
- public String call() throws Throwable {
- return null;
- }
- }, 10);
- }
- Thread.sleep(10);
-
- final long finishNumberOfThreads = Thread.getAllStackTraces().size();
-
- assertTrue("The number of threads have grown significantly. start: " + startNumberOfThreads + ", end:" + finishNumberOfThreads,
- Math.abs(finishNumberOfThreads - startNumberOfThreads) < 5);
-
- }
-
@Test(expected = TimeoutException.class)
public void times_out_infinite_loop_if_it_takes_too_long() throws Throwable {
final Slow slow = new Slow();
@@ -69,8 +45,28 @@ public Void call() throws Throwable {
fail();
}
+ @Test
+ public void doesnt_leak_threads() throws Throwable {
+ long initialNumberOfThreads = Thread.getAllStackTraces().size();
+ boolean cleanedUp = false;
+ for (int i = 0; i < 1000; i++) {
+ Timeout.timeout(new Timeout.Callback<String>() {
+ @Override
+ public String call() throws Throwable {
+ return null;
+ }
+ }, 10);
+ Thread.sleep(5);
+ long currentNumberOfThreads = Thread.getAllStackTraces().size();
+ if (i > 20 && currentNumberOfThreads == initialNumberOfThreads) {
+ cleanedUp = true;
+ break;
+ }
+ }
+ assertTrue("Threads weren't cleaned up", cleanedUp);
+ }
public static class Slow {
public String slow() throws InterruptedException {
Please sign in to comment.
Something went wrong with that request. Please try again.