-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathscripts.gradle.kts
More file actions
25 lines (24 loc) · 1.48 KB
/
scripts.gradle.kts
File metadata and controls
25 lines (24 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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")
val parallelForks = (Runtime.getRuntime().availableProcessors() / 2).coerceAtLeast(1)
test.maxParallelForks = parallelForks
test.doFirst {
println("$test setting maxParallelForks to $parallelForks")
}
}