-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor with enableTestConcurrency function
- Loading branch information
Showing
6 changed files
with
48 additions
and
87 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
extra["enableTestConcurrency"] = | ||
fun(test: Test) { | ||
test.systemProperty("junit.jupiter.execution.parallel.enabled", true) | ||
// Use PER_METHOD test instance life cycle. This avoids the race condition when tests are run in | ||
// parallel mode and | ||
// if the test class has a non-static fields. The non-static fields are shared across all test | ||
// methods. If the life cycle is not PER_METHOD, the test methods may overwrite the fields and | ||
// cause test failures. | ||
// | ||
// However, the life cycle can still be over-written by @TestInstance(Lifecycle) annotation. | ||
// See https://junit.org/junit5/docs/current/user-guide/#writing-tests-parallel-execution | ||
test.systemProperty("junit.jupiter.testinstance.lifecycle.default", "per_method") | ||
// Allocate thread count based on available processors | ||
test.systemProperty("junit.jupiter.execution.parallel.config.strategy", "dynamic") | ||
// Set default parallel mode to same thread. All tests within a class are run in sequence. | ||
test.systemProperty("junit.jupiter.execution.parallel.mode.default", "concurrent") | ||
// Set default parallel mode for classes to concurrent. All test classes are run in parallel. | ||
test.systemProperty("junit.jupiter.execution.parallel.mode.classes.default", "concurrent") | ||
|
||
test.maxParallelForks = | ||
(Runtime.getRuntime().availableProcessors() / 2).coerceAtLeast(1).also { | ||
println("$test setting maxParallelForks to $it") | ||
} | ||
} |