-
Notifications
You must be signed in to change notification settings - Fork 623
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add cancel of TestCaseExecutor interruption job if test succeeds (#590)
* Add cancel of TestCaseExecutor interruption job if test succeeds 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 * Implemented new "junit" style approach to the test timeouts #588
- Loading branch information
Showing
6 changed files
with
109 additions
and
43 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
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
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
45 changes: 45 additions & 0 deletions
45
.../kotlintest-tests-core/src/test/kotlin/com/sksamuel/kotlintest/MultipleTestTimeoutTest.kt
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,45 @@ | ||
package com.sksamuel.kotlintest | ||
|
||
import io.kotlintest.milliseconds | ||
import io.kotlintest.specs.FreeSpec | ||
|
||
class MultipleTestTimeoutTest : FreeSpec() { | ||
|
||
// The test executor was failing because as it reutilizes some threads from a thread pool. | ||
// When using that thread pool, a task to cancel the thread is created, so that the engine can interrupt | ||
// a test that is going forever. | ||
// However, if the task is not cancelled, it will eventually interrupt the thread when it's running another task | ||
// in the thread pool, interrupting a test that hasn't timed out yet, which is undesired. | ||
|
||
init { | ||
// 100 millis sleep will "accumulate" between tests. If the context is still shared, one of them will fail | ||
// due to timeout. | ||
"Test 1".config(timeout = 300.milliseconds) { | ||
Thread.sleep(100) | ||
} | ||
|
||
"Test 2".config(timeout = 300.milliseconds) { | ||
Thread.sleep(100) | ||
} | ||
|
||
"Test 3".config(timeout = 300.milliseconds) { | ||
Thread.sleep(100) | ||
} | ||
|
||
"Test 4".config(timeout = 300.milliseconds) { | ||
Thread.sleep(100) | ||
} | ||
|
||
"Test 5".config(timeout = 300.milliseconds) { | ||
Thread.sleep(100) | ||
} | ||
|
||
"Test 6".config(timeout = 300.milliseconds) { | ||
Thread.sleep(100) | ||
} | ||
|
||
"Test 7".config(timeout = 300.milliseconds) { | ||
Thread.sleep(100) | ||
} | ||
} | ||
} |
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
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