From 2a7a20dd99982a18587af513fefc5d6cd4e26664 Mon Sep 17 00:00:00 2001 From: Dmitriy Novozhilov Date: Wed, 24 Feb 2021 14:03:54 +0300 Subject: [PATCH] [Test] Add ability to set maximum of working threads for parallel JUnit 5 tests --- .../testResources/junit-platform.properties | 3 ++ ...dParallelExecutionConfigurationStrategy.kt | 34 +++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 compiler/tests-common-new/tests/org/jetbrains/kotlin/test/DynamicWithMaxThresholdParallelExecutionConfigurationStrategy.kt diff --git a/compiler/tests-common-new/testResources/junit-platform.properties b/compiler/tests-common-new/testResources/junit-platform.properties index dd6225018bb..1c0ce1e7d48 100644 --- a/compiler/tests-common-new/testResources/junit-platform.properties +++ b/compiler/tests-common-new/testResources/junit-platform.properties @@ -1,2 +1,5 @@ junit.jupiter.execution.parallel.enabled=true junit.jupiter.execution.parallel.mode.default=concurrent +junit.jupiter.execution.parallel.config.strategy=custom +junit.jupiter.execution.parallel.config.custom.class=org.jetbrains.kotlin.test.DynamicWithMaxThresholdParallelExecutionConfigurationStrategy +junit.jupiter.execution.parallel.config.fixed.threshold=16 diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/DynamicWithMaxThresholdParallelExecutionConfigurationStrategy.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/DynamicWithMaxThresholdParallelExecutionConfigurationStrategy.kt new file mode 100644 index 00000000000..ccd9f601b46 --- /dev/null +++ b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/DynamicWithMaxThresholdParallelExecutionConfigurationStrategy.kt @@ -0,0 +1,34 @@ +/* + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.test + +import org.junit.platform.engine.ConfigurationParameters +import org.junit.platform.engine.support.hierarchical.ParallelExecutionConfiguration +import org.junit.platform.engine.support.hierarchical.ParallelExecutionConfigurationStrategy + +class DynamicWithMaxThresholdParallelExecutionConfigurationStrategy : ParallelExecutionConfigurationStrategy { + companion object { + // Full property name is junit.jupiter.execution.parallel.config.fixed.threshold + private const val FIXED_THRESHOLD = "fixed.threshold" + private const val DEFAULT_VALUE = 16 + + // Copied from org.junit.platform.engine.support.hierarchical.DefaultParallelExecutionConfigurationStrategy + private const val KEEP_ALIVE_SECONDS = 30 + } + + override fun createConfiguration(configurationParameters: ConfigurationParameters): ParallelExecutionConfiguration { + val threshold = configurationParameters[FIXED_THRESHOLD].map { it.toIntOrNull() }.orElse(null) ?: DEFAULT_VALUE + val cpuCores = Runtime.getRuntime().availableProcessors() + val parallelism = if (threshold > 0) minOf(cpuCores, threshold) else cpuCores + return object : ParallelExecutionConfiguration { + override fun getParallelism(): Int = parallelism + override fun getMinimumRunnable(): Int = parallelism + override fun getMaxPoolSize(): Int = 256 + parallelism + override fun getCorePoolSize(): Int = parallelism + override fun getKeepAliveSeconds(): Int = KEEP_ALIVE_SECONDS + } + } +}