Skip to content

Commit

Permalink
Work on issue junit-team#1365, cleared interrupt status flag in runLe…
Browse files Browse the repository at this point in the history
…af method of parent runner
  • Loading branch information
npathai committed Oct 26, 2018
1 parent 67d424b commit d08e7ad
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/main/java/org/junit/runners/ParentRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ protected final void runLeaf(Statement statement, Description description,
eachNotifier.addFailure(e);
} finally {
eachNotifier.fireTestFinished();
Thread.interrupted(); // clear the interrupt status flag for test isolation
}
}

Expand Down
43 changes: 43 additions & 0 deletions src/test/java/org/junit/tests/running/classes/ThreadsTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package org.junit.tests.running.classes;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;

import org.junit.Test;
import org.junit.runner.Description;
import org.junit.runner.JUnitCore;
import org.junit.runner.Result;
import org.junit.runner.notification.RunListener;

public class ThreadsTest {

public static class TestWithInterrupt {

@Test
public void interruptCurrentThread() {
assertFalse(Thread.interrupted());

Thread.currentThread().interrupt();
}

@Test
public void otherTestCase() {
assertFalse(Thread.interrupted());

Thread.currentThread().interrupt();
}
}

@Test
public void interruptStatusIsClearedAfterTestExecution() {
JUnitCore jUnitCore = new JUnitCore();
jUnitCore.addListener(new RunListener() {
@Override
public void testStarted(Description description) {
System.out.println(description.getMethodName());
}
});

Result result = jUnitCore.run(TestWithInterrupt.class);
assertEquals(0, result.getFailureCount());
}
}

0 comments on commit d08e7ad

Please sign in to comment.