Skip to content

Commit e5d469c

Browse files
mmollaverdisvc-squareup-copybara
authored andcommitted
Parallel tests - log the partitioned DB name to help
debugging GitOrigin-RevId: f3177f19818338d36f541155590cbe071a9a13f6
1 parent caaae4b commit e5d469c

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

misk-jdbc/src/testFixtures/kotlin/misk/jdbc/ParitionedDataSourceConfig.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
package misk.jdbc
22

33
import misk.testing.updateForParallelTests
4+
import wisp.logging.getLogger
5+
6+
private val logger = getLogger<DataSourceConfig>()
47

58
fun DataSourceConfig.updateForParallelTests(): DataSourceConfig = this.updateForParallelTests { config, partitionId ->
6-
config.copy(database = "${config.database}_$partitionId")
9+
val partitionedDatabaseName = "${config.database}_$partitionId"
10+
logger.info { "Test running in parallel - using $partitionedDatabaseName database" }
11+
config.copy(database = partitionedDatabaseName)
712
}
813

914
fun DataSourceClusterConfig.updateForParallelTests(): DataSourceClusterConfig = this.copy(

misk-testing/src/main/kotlin/misk/testing/ParallelTests.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ internal object ParallelTests {
1111
*
1212
* This assumes that the environment variable `MAX_TEST_PARALLEL_FORKS` is set to the number of `maxParallelForks`.
1313
*/
14-
internal fun partitioned(): PartitionedTest {
14+
internal fun isPartitioned(): PartitionedTest {
1515
val maxTestPartitions = System.getenv("MAX_TEST_PARALLEL_FORKS")?.toInt()
1616
return if (maxTestPartitions != null && maxTestPartitions > 1) {
1717
val testWorkerId = System.getProperty("org.gradle.test.worker", "0").toInt()
@@ -29,8 +29,8 @@ internal sealed interface PartitionedTest {
2929
}
3030

3131
/**
32-
* Applies the `update` function to the given `T`, if the tests are running in parallel
33-
* (with Gradle's `maxParallelForks`). The `update` function is also passed the partition ID.
32+
* Applies the `update` lambda to the given `T`, if the tests are running in parallel
33+
* (with Gradle's `maxParallelForks`).
3434
*
3535
* This can be used for updating configurations for the purpose of providing isolation between
3636
* tests running across different parallel processes, such as appending the partition ID to the database name,
@@ -39,7 +39,7 @@ internal sealed interface PartitionedTest {
3939
* This assumes that the environment variable `MAX_TEST_PARALLEL_FORKS` is set to the number of `maxParallelForks`.
4040
*/
4141
fun <T> T.updateForParallelTests(update: (T, Int) -> T): T {
42-
return when (val partitionedTest = ParallelTests.partitioned()) {
42+
return when (val partitionedTest = ParallelTests.isPartitioned()) {
4343
is PartitionedTest.Partitioned -> {
4444
update(this, partitionedTest.partitionId)
4545
}

0 commit comments

Comments
 (0)