-
Notifications
You must be signed in to change notification settings - Fork 649
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
Add cancel of TestCaseExecutor interruption job if test succeeds #590
Add cancel of TestCaseExecutor interruption job if test succeeds #590
Conversation
@sksamuel @sschuberth This scenario exercises my main hypothesis of "I believe the tests are sharing a timeout". It works by creating a big timeout that will be "accumulated" between tests, and one of the tests will have a "Thread.sleep interrupted" message. This, I believe, is the executor being shutdown from another test. When I added a |
If you remove the |
c44672f
to
fb5b43e
Compare
fb5b43e
to
40f91b1
Compare
...st-runner/kotlintest-runner-jvm/src/main/kotlin/io/kotlintest/runner/jvm/TestCaseExecutor.kt
Outdated
Show resolved
Hide resolved
...-tests/kotlintest-tests-core/src/test/kotlin/com/sksamuel/kotlintest/TestCaseExecutorTest.kt
Outdated
Show resolved
Hide resolved
...-tests/kotlintest-tests-core/src/test/kotlin/com/sksamuel/kotlintest/TestCaseExecutorTest.kt
Outdated
Show resolved
Hide resolved
...-tests/kotlintest-tests-core/src/test/kotlin/com/sksamuel/kotlintest/TestCaseExecutorTest.kt
Outdated
Show resolved
Hide resolved
40f91b1
to
2b8d7fe
Compare
|
||
// This cancel is necessary, or else the scheduler is reutilized by another test, and the shutdown will happen | ||
// in the other test. This leads to tests "sharing" a timeout, and another test being timed out due to this task. | ||
scheduledInterrupt.cancel(false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm confused by this. If the scheduled runnable still runs, all it does is shutdown the executor. The executor that will have already been shutdown, so what's the issue? There's no problem if it still runs right.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm also pretty confused by this, as the Executor should be a different one every time. However, the issue seems to be on TestEngineListener
, as it's shared between tests. executor
will be listenerExecutor
for single-threaded tests, and these will be interrupted as the executor shuts down
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although I'm not completely sure if this is a Threads
issue or a Coroutines
issue of some sort, preventing the executor from shutting down if the test completes will fix the scenario that I created in TestCaseExecutorTest
Running more tests now it made me realize this error has nothing to do with a threadpool. I'll remove it from the test scenario |
The error is specifically with |
As it is, the current TestCaseExecutor will by mistake recycle a thread from a threadpool between multiple test executions. That shouldn't be a problem. However, the scheduler will cancel the executor after a timeout has passed, and if another thread is running there, it will be interrupted. This interruption is undesired, as it had nothing to do with the thread that successfully passed without a timeout. This commit cancels the interruption job if the test ran successfully, avoiding this issue. Fixes #588
2b8d7fe
to
ce3e124
Compare
The error is what you said earlier I think. |
Ok, so there are two options. I think it makes more sense to cancel the task |
Cancel won't do anything unless the user checks for it in their code. Which they won't 99% of the time. The solution is to not share the listener executor. Always create a new one every time. Hmm... |
What do you mean with this? This have nothing to do with user code, unless the code doesn't respons to a |
Yes I meant the coroutine. We can cancel the scheduler but it won't help. |
I think my original approach is wrong, and kotlintest 3.2.0 is fundamentally broken on test suites that run for over 10 minutes that use threads=1 because they all share the listener executor. Calling cancel on the scheduler - there's no point even adding it in the first place as we cannot interrupt this executor full stop. This is my proposal. For each spec we create a new single threaded listener executor (delete the old shared executor). Only then do we call shutdown on the listener executor (and the test executor if threads>1). I don't like it as it's just not correct to leave the threads running in the background but I'm not sure what else we can do. |
I don't think leaving threads running isn't a biiiig problem. As you said, users are on their own if their threads are not interruptable and run indefinetly. This is such a rare scenario that I don't think will even happen. I'll try to implement your proposal and add it to this commit if you won't focus on this now. |
But if you want to take it and use this branch, let me know |
We should fix it ASAP, as this will break a lot of test suites in 3.2.0 |
If you want to add the cancel on the scheduler as a hotfix now, while we implement the correct fix, I'm for it aswell. |
I'm trying to ignore the Let me know if you think differently |
I can fix and release tonight if you want me to do it. |
Sure thing, I think it will be better if you do it. Use this branch if you want, as the test can be used from it. |
Ok
…On Fri, 18 Jan 2019 at 12:02, Leonardo Colman Lopes < ***@***.***> wrote:
Sure thing, I think it will be better if you do it.
I don't have a lot of experience on these runners.
Use this branch if you will, as the test can be used from it.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#590 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAtZGo1VRDvhP5m-aZn9Aa5AgZaCKDipks5vEbfogaJpZM4aG_hv>
.
|
All tests now pass using an implementation as I described earlier. |
As it is, the current TestCaseExecutor will by mistake recycle a thread from a threadpool between multiple test executions. That shouldn't be a problem. However, the scheduler will cancel the executor after a timeout has passed, and if another thread is running there, it will be interrupted.
This interruption is undesired, as it had nothing to do with the thread that successfully passed without a timeout.
This commit cancels the interruption job if the test ran successfully, avoiding this issue.
Fixes #588