-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Interrupted test cases cause random failures with thread reuse #1365
Comments
Thanks for the bug report. I wonder if JUnit should cause an otherwise passing test to fail if the interrupted bit was set during the test run. I am guessing no, because so many otherwise passing tests would start failing, and the fix would be to sprinkle There is also the question of whether @junit-team/junit-committers thoughts? |
I would support the idea to call |
@kcooney I can start working on this. |
@npathai fantastic! There is still an open question of whether |
IMHO we should clear the interrupted flag after each test. We should not clear it in @kcooney can you please explain why you think that |
@stefanbirkner the general guidance I've read is any time you catch |
FWIW, I did a quick search in GitHub for calls to |
@kcooney @stefanbirkner I was wondering how IDE's integrate with JUnit framework. If I have long running test case something like @Test
public void test1() throws InterruptedException {
Thread.sleep(100000);
}
@Test
public void test2() throws InterruptedException {
Thread.sleep(100000);
} and I stop the test case forcefully using IDE. Will the IDE interrupt the Thread running JUnit tests or something else? My doubt is in a way we are violating I apologize if the question is dumb, I don't have experience with how IDE's integrate. It will be great if you can shed some light for me. |
…af method of parent runner
…in separate method. Refactored the way thread interrupted status is checked in Unit test
@ npathai I think IDEs call |
So it sounds like the concerns is this: what happens if the IDE calls If that thread is not in a blocking method and doesn't call a blocking method, the the test run will abort after the current test complets (due to If that thread is in a blocking method or calls a blocking method, it will throw If the test swallows the exception things get tricky. |
We use pleaseStop() in Surefire. We rely on current behavior that the
JUnit's Scheduler stops scheduling a new Runnable (test method) but the
pending method goes on.
…On Fri, Nov 9, 2018 at 5:48 PM Kevin Cooney ***@***.***> wrote:
So it sounds like the concerns is this: what happens if the IDE calls
pleaseStop() then Thread.interrupt() on the thread running the tests?
If that thread is not in a blocking method and doesn't call a blocking
method, the the test run will abort after the current test complets (due to
pleaseStop()
If that thread is in a blocking method or calls a blocking method, it will
throw InterruptedException. If the test doesn't catch that exception it
will fail, then the test run will abort.
If the test swallows the exception things get tricky.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#1365 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AA_yR9IgJF3rTXtFz9y9EIBig914twYYks5utbHrgaJpZM4KIg2k>
.
--
Cheers
Tibor
|
…hread interrupted call from ParentRunner to BlockJUnit4ClassRunner methodBlock()
…s well, so that interrupt status is cleared if it is set from @afterclass or ClassRule
… removed unused import
…classBlock() and methodBlock(). The flag is cleared after each test case completes and after AfterClass/ClassRule are executed
…classBlock() and methodBlock(). The flag is cleared after each test case completes and after AfterClass/ClassRule are executed
The thread interrupt status flag is now cleared from `classBlock()` and `methodBlock()`. The flag is cleared after each test case completes and after `AfterClass` methods and `ClassRules` have been executed. Fixes #1365.
The thread interrupt status flag is now cleared from `classBlock()` and `methodBlock()`. The flag is cleared after each test case completes and after `AfterClass` methods and `ClassRules` have been executed. Fixes #1365.
The thread interrupt status flag is now cleared from `classBlock()` and `methodBlock()`. The flag is cleared after each test case completes and after `AfterClass` methods and `ClassRules` have been executed. Fixes #1365.
The thread interrupt status flag is now cleared from `classBlock()` and `methodBlock()`. The flag is cleared after each test case completes and after `AfterClass` methods and `ClassRules` have been executed. Fixes #1365.
Shouldn't this be cherry-picked to JUnit 5? I'm having the same issue with 5.3.2. |
@joaodias14 Please upgrade to the latest version, it was fixed in 5.4.0 (see junit-team/junit5#1688). |
Many thanks @marcphilipp! |
The thread interrupt status flag is now cleared from `classBlock()` and `methodBlock()`. The flag is cleared after each test case completes and after `AfterClass` methods and `ClassRules` have been executed. Fixes junit-team#1365.
…hread reuse (porting [the earlier fix in JUnit4](junit-team/junit4#1365))
Whenever a test case is interrupted (Thread.interrupt()), the test runner thread seems to stay in interrupted state. This causes random failures later when the thread is reused for other test cases.
Expected behaviour: When the thread is reused, interrupted flag for the thread is cleaned before starting a new test case. This can be done by calling
Thread.interrupted()
, which returns the interrupted state, and clears the interrupted flag.The following code should reproduce the problem, given that test1 is run before test2
The problem I encountered is similar to the one described in https://www.thoughtwire.com/junit-interupt/
The text was updated successfully, but these errors were encountered: