-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for test sharding (#272)
* Add a common testutil module for shared helpers * Introduce ShardingFilter and mirror support for 'numShards' and 'shardIndex'
- Loading branch information
1 parent
6def54e
commit 26cd58e
Showing
22 changed files
with
444 additions
and
126 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
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
82 changes: 0 additions & 82 deletions
82
instrumentation/core/src/test/java/de/mannodermaus/junit5/util/AndroidBuildUtils.kt
This file was deleted.
Oops, something went wrong.
25 changes: 0 additions & 25 deletions
25
instrumentation/core/src/test/java/de/mannodermaus/junit5/util/StubInstrumentation.java
This file was deleted.
Oops, something went wrong.
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
53 changes: 53 additions & 0 deletions
53
...tation/runner/src/main/kotlin/de/mannodermaus/junit5/internal/discovery/ShardingFilter.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,53 @@ | ||
package de.mannodermaus.junit5.internal.discovery | ||
|
||
import android.os.Bundle | ||
import de.mannodermaus.junit5.internal.extensions.isDynamicTest | ||
import org.junit.platform.engine.FilterResult | ||
import org.junit.platform.engine.TestDescriptor | ||
import org.junit.platform.launcher.PostDiscoveryFilter | ||
import org.junit.platform.launcher.TestIdentifier | ||
import kotlin.math.abs | ||
|
||
/** | ||
* JUnit 5 implementation of the default instrumentation's | ||
* `androidx.test.internal.runner.TestRequestBuilder$ShardingFilter`, | ||
* ported to the new API to support dynamic test templates, too. | ||
* | ||
* Based on a draft by KyoungJoo Jeon (@jkj8790). | ||
*/ | ||
internal class ShardingFilter( | ||
private val numShards: Int, | ||
private val shardIndex: Int, | ||
) : PostDiscoveryFilter { | ||
|
||
companion object { | ||
private const val ARG_NUM_SHARDS = "numShards" | ||
private const val ARG_SHARD_INDEX = "shardIndex" | ||
|
||
fun fromArguments(arguments: Bundle): ShardingFilter? { | ||
val numShards = arguments.getString(ARG_NUM_SHARDS)?.toInt() ?: -1 | ||
val shardIndex = arguments.getString(ARG_SHARD_INDEX)?.toInt() ?: -1 | ||
|
||
return if (numShards > 0 && shardIndex >= 0 && shardIndex < numShards) { | ||
ShardingFilter(numShards, shardIndex) | ||
} else { | ||
null | ||
} | ||
} | ||
} | ||
|
||
override fun apply(descriptor: TestDescriptor): FilterResult { | ||
val identifier = TestIdentifier.from(descriptor) | ||
|
||
if (identifier.isTest || identifier.isDynamicTest) { | ||
val remainder = abs(identifier.hashCode()) % numShards | ||
return if (remainder == shardIndex) { | ||
FilterResult.included(null) | ||
} else { | ||
FilterResult.excluded("excluded") | ||
} | ||
} | ||
|
||
return FilterResult.included(null) | ||
} | ||
} |
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
Oops, something went wrong.