Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #490 Rename testShards to maxTestShards #514

Merged
merged 1 commit into from
Mar 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions test_runner/flank.ios.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ flank:

## test shards - the amount of groups to split the test suite into
## set to -1 to use one shard per test. default: 1
# testShards: 1
# maxTestShards: 1

## shard time - the amount of time tests within a shard should take
## when set to > 0, the shard count is dynamically set based on time up to the maxmimum limit defined by testShards
## when set to > 0, the shard count is dynamically set based on time up to the maxmimum limit defined by maxTestShards
## 2 minutes (120) is recommended.
## default: -1 (unlimited)
# shardTime: -1
Expand Down
4 changes: 2 additions & 2 deletions test_runner/flank.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ flank:

## test shards - the amount of groups to split the test suite into
## set to -1 to use one shard per test. default: 1
# testShards: 1
# maxTestShards: 1

## shard time - the amount of time tests within a shard should take
## when set to > 0, the shard count is dynamically set based on time up to the maxmimum limit defined by testShards
## when set to > 0, the shard count is dynamically set based on time up to the maxmimum limit defined by maxTestShards
## 2 minutes (120) is recommended.
## default: -1 (unlimited)
# shardTime: -1
Expand Down
4 changes: 2 additions & 2 deletions test_runner/src/main/kotlin/ftl/args/AndroidArgs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class AndroidArgs(
val devices = cli?.device ?: androidGcloud.device

private val flank = flankYml.flank
override val testShards = cli?.testShards ?: flank.testShards
override val maxTestShards = cli?.maxTestShards ?: flank.maxTestShards
override val shardTime = cli?.shardTime ?: flank.shardTime
override val repeatTests = cli?.repeatTests ?: flank.repeatTests
override val smartFlankGcsPath = flank.smartFlankGcsPath
Expand Down Expand Up @@ -163,7 +163,7 @@ ${devicesToString(devices)}
flaky-test-attempts: $flakyTestAttempts

flank:
testShards: $testShards
maxTestShards: $maxTestShards
shardTime: $shardTime
repeatTests: $repeatTests
smartFlankGcsPath: $smartFlankGcsPath
Expand Down
2 changes: 1 addition & 1 deletion test_runner/src/main/kotlin/ftl/args/IArgs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ interface IArgs {
val flakyTestAttempts: Int

// FlankYml
val testShards: Int
val maxTestShards: Int
val shardTime: Int
val repeatTests: Int
val smartFlankGcsPath: String
Expand Down
4 changes: 2 additions & 2 deletions test_runner/src/main/kotlin/ftl/args/IosArgs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class IosArgs(
val devices = cli?.device ?: iosGcloud.device

private val flank = flankYml.flank
override val testShards = cli?.testShards ?: flank.testShards
override val maxTestShards = cli?.maxTestShards ?: flank.maxTestShards
override val shardTime = cli?.shardTime ?: flank.shardTime
override val repeatTests = cli?.repeatTests ?: flank.repeatTests
override val smartFlankGcsPath = flank.smartFlankGcsPath
Expand Down Expand Up @@ -119,7 +119,7 @@ ${devicesToString(devices)}
flaky-test-attempts: $flakyTestAttempts

flank:
testShards: $testShards
maxTestShards: $maxTestShards
shardTime: $shardTime
repeatTests: $repeatTests
smartFlankGcsPath: $smartFlankGcsPath
Expand Down
6 changes: 3 additions & 3 deletions test_runner/src/main/kotlin/ftl/args/yml/FlankYml.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import ftl.util.Utils.fatalError
/** Flank specific parameters for both iOS and Android */
@JsonIgnoreProperties(ignoreUnknown = true)
class FlankYmlParams(
val testShards: Int = 1,
val maxTestShards: Int = 1,
val shardTime: Int = -1,
val repeatTests: Int = 1,
val smartFlankGcsPath: String = "",
Expand All @@ -22,12 +22,12 @@ class FlankYmlParams(
) {
companion object : IYmlKeys {
override val keys = listOf(
"testShards", "shardTime", "repeatTests", "smartFlankGcsPath", "disableSharding", "test-targets-always-run", "files-to-download"
"maxTestShards", "shardTime", "repeatTests", "smartFlankGcsPath", "disableSharding", "test-targets-always-run", "files-to-download"
)
}

init {
if (testShards <= 0 && testShards != -1) fatalError("testShards must be >= 1 or -1")
if (maxTestShards <= 0 && maxTestShards != -1) fatalError("maxTestShards must be >= 1 or -1")
if (shardTime <= 0 && shardTime != -1) fatalError("shardTime must be >= 1 or -1")
if (repeatTests < 1) fatalError("repeatTests must be >= 1")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ class AndroidRunCommand : Runnable {
names = ["--test-shards"],
description = ["The amount of matrices to split the tests across."]
)
var testShards: Int? = null
var maxTestShards: Int? = null

@Option(
names = ["--shard-time"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class IosRunCommand : Runnable {
names = ["--test-shards"],
description = ["The amount of matrices to split the tests across."]
)
var testShards: Int? = null
var maxTestShards: Int? = null

@Option(
names = ["--shard-time"],
Expand Down
8 changes: 4 additions & 4 deletions test_runner/src/main/kotlin/ftl/shard/Shard.kt
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ object Shard {
val shardsByTime = Math.ceil(testsTotalTime / args.shardTime).toInt()

// If there is no limit, use the calculated amount
if (args.testShards == -1) {
if (args.maxTestShards == -1) {
return shardsByTime
}

// We need to respect the testShards
return Math.min(shardsByTime, args.testShards)
// We need to respect the maxTestShards
return Math.min(shardsByTime, args.maxTestShards)
}

// take in the XML with timing info then return list of shards based on the amount of shards to use
Expand All @@ -81,7 +81,7 @@ object Shard {
args: IArgs,
forcedShardCount: Int = -1
): List<TestShard> {
val maxShards = if (forcedShardCount == -1) args.testShards else forcedShardCount
val maxShards = if (forcedShardCount == -1) args.maxTestShards else forcedShardCount
val junitMap = createJunitMap(oldTestResult, args)

var cacheMiss = 0
Expand Down
14 changes: 7 additions & 7 deletions test_runner/src/test/kotlin/ftl/args/AndroidArgsFileTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ class AndroidArgsFileTest {
}

with(args) {
assert(testShards, 1)
assert(maxTestShards, 1)
assert(repeatTests, 1)
}
}

private fun configWithTestMethods(amount: Int, testShards: Int = 1): AndroidArgs {
private fun configWithTestMethods(amount: Int, maxTestShards: Int = 1): AndroidArgs {

return AndroidArgs(
GcloudYml(GcloudYmlParams()),
Expand All @@ -104,7 +104,7 @@ class AndroidArgsFileTest {
),
FlankYml(
FlankYmlParams(
testShards = testShards
maxTestShards = maxTestShards
)
),
""
Expand All @@ -122,7 +122,7 @@ class AndroidArgsFileTest {
fun calculateShards_1() {
val config = configWithTestMethods(1)
with(config) {
assert(testShards, 1)
assert(maxTestShards, 1)
assert(testShardChunks.size, 1)
assert(testShardChunks.first().size, 1)
}
Expand All @@ -132,17 +132,17 @@ class AndroidArgsFileTest {
fun calculateShards_155() {
val config = configWithTestMethods(155)
with(config) {
assert(testShards, 1)
assert(maxTestShards, 1)
assert(testShardChunks.size, 1)
assert(testShardChunks.first().size, 155)
}
}

@Test
fun calculateShards_155_40() {
val config = configWithTestMethods(155, testShards = 40)
val config = configWithTestMethods(155, maxTestShards = 40)
with(config) {
assert(testShards, 40)
assert(maxTestShards, 40)
assert(testShardChunks.size, 40)
assert(testShardChunks.first().size, 3)
}
Expand Down
20 changes: 10 additions & 10 deletions test_runner/src/test/kotlin/ftl/args/AndroidArgsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class AndroidArgsTest {
flaky-test-attempts: 3

flank:
testShards: 7
maxTestShards: 7
shardTime: 60
repeatTests: 8
files-to-download:
Expand Down Expand Up @@ -160,7 +160,7 @@ class AndroidArgsTest {
assert(flakyTestAttempts, 3)

// FlankYml
assert(testShards, 7)
assert(maxTestShards, 7)
assert(shardTime, 60)
assert(repeatTests, 8)
assert(filesToDownload, listOf("/sdcard/screenshots", "/sdcard/screenshots2"))
Expand Down Expand Up @@ -215,7 +215,7 @@ AndroidArgs
flaky-test-attempts: 3

flank:
testShards: 7
maxTestShards: 7
shardTime: 60
repeatTests: 8
smartFlankGcsPath:${' '}
Expand Down Expand Up @@ -261,7 +261,7 @@ AndroidArgs
assert(flakyTestAttempts, 0)

// FlankYml
assert(testShards, 1)
assert(maxTestShards, 1)
assert(repeatTests, 1)
assert(filesToDownload, empty)
assert(testTargetsAlwaysRun, empty)
Expand All @@ -278,12 +278,12 @@ AndroidArgs
test: $testErrorApk

flank:
testShards: -1
maxTestShards: -1
"""
)

with(androidArgs) {
assert(testShards, -1)
assert(maxTestShards, -1)
assert(testShardChunks.size, 2)
testShardChunks.forEach { chunk -> assert(chunk.size, 1) }
}
Expand Down Expand Up @@ -683,7 +683,7 @@ AndroidArgs
}

@Test
fun cli_testShards() {
fun cli_maxTestShards() {
val cli = AndroidRunCommand()
CommandLine(cli).parse("--test-shards=3")

Expand All @@ -693,10 +693,10 @@ AndroidArgs
test: $testApk

flank:
testShards: 2
maxTestShards: 2
"""
assertThat(AndroidArgs.load(yaml).testShards).isEqualTo(2)
assertThat(AndroidArgs.load(yaml, cli).testShards).isEqualTo(3)
assertThat(AndroidArgs.load(yaml).maxTestShards).isEqualTo(2)
assertThat(AndroidArgs.load(yaml, cli).maxTestShards).isEqualTo(3)
}

@Test
Expand Down
10 changes: 5 additions & 5 deletions test_runner/src/test/kotlin/ftl/args/FlankYmlTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@ class FlankYmlTest {
@Test
fun testValidArgs() {
FlankYml()
FlankYml(FlankYmlParams(testShards = -1))
val yml = FlankYml(FlankYmlParams(testShards = 1, repeatTests = 1, shardTime = 58))
FlankYml(FlankYmlParams(maxTestShards = -1))
val yml = FlankYml(FlankYmlParams(maxTestShards = 1, repeatTests = 1, shardTime = 58))
assertThat(yml.flank.repeatTests).isEqualTo(1)
assertThat(yml.flank.testShards).isEqualTo(1)
assertThat(yml.flank.maxTestShards).isEqualTo(1)
assertThat(yml.flank.shardTime).isEqualTo(58)
assertThat(yml.flank.testTargetsAlwaysRun).isEqualTo(emptyList<String>())
assertThat(FlankYml.map).isNotEmpty()
}

@Test
fun testInvalidTestShards() {
exceptionRule.expectMessage("testShards must be >= 1 or -1")
FlankYml(FlankYmlParams(testShards = -2))
exceptionRule.expectMessage("maxTestShards must be >= 1 or -1")
FlankYml(FlankYmlParams(maxTestShards = -2))
}

@Test
Expand Down
2 changes: 1 addition & 1 deletion test_runner/src/test/kotlin/ftl/args/IosArgsFileTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class IosArgsFileTest {
Device("iphone8", "11.2", "en_US", "portrait")
)
)
assert(testShards, 1)
assert(maxTestShards, 1)
assert(repeatTests, 1)
}
}
Expand Down
20 changes: 10 additions & 10 deletions test_runner/src/test/kotlin/ftl/args/IosArgsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class IosArgsTest {
flaky-test-attempts: 4

flank:
testShards: 7
maxTestShards: 7
shardTime: 60
repeatTests: 8
files-to-download:
Expand Down Expand Up @@ -121,7 +121,7 @@ class IosArgsTest {
assert(devices, listOf(device, device))

// FlankYml
assert(testShards, 7)
assert(maxTestShards, 7)
assert(shardTime, 60)
assert(repeatTests, 8)
assert(testTargetsAlwaysRun, listOf("a/testGrantPermissions", "a/testGrantPermissions2"))
Expand Down Expand Up @@ -164,7 +164,7 @@ IosArgs
flaky-test-attempts: 4

flank:
testShards: 7
maxTestShards: 7
shardTime: 60
repeatTests: 8
smartFlankGcsPath:${' '}
Expand Down Expand Up @@ -207,7 +207,7 @@ IosArgs
assert(flakyTestAttempts, 0)

// FlankYml
assert(testShards, 1)
assert(maxTestShards, 1)
assert(shardTime, -1)
assert(repeatTests, 1)
assert(testTargetsAlwaysRun, emptyList<String>())
Expand All @@ -228,12 +228,12 @@ IosArgs
xctestrun-file: $xctestrunFile

flank:
testShards: -1
maxTestShards: -1
"""
)

with(iosArgs) {
assert(testShards, -1)
assert(maxTestShards, -1)
assert(testShardChunks.size, 17)
testShardChunks.forEach { chunk -> assert(chunk.size, 1) }
}
Expand Down Expand Up @@ -389,7 +389,7 @@ IosArgs
}

@Test
fun cli_testShards() {
fun cli_maxTestShards() {
val cli = IosRunCommand()
CommandLine(cli).parse("--test-shards=3")

Expand All @@ -399,10 +399,10 @@ IosArgs
xctestrun-file: $xctestrunFile

flank:
testShards: 2
maxTestShards: 2
"""
assertThat(IosArgs.load(yaml).testShards).isEqualTo(2)
assertThat(IosArgs.load(yaml, cli).testShards).isEqualTo(3)
assertThat(IosArgs.load(yaml).maxTestShards).isEqualTo(2)
assertThat(IosArgs.load(yaml, cli).maxTestShards).isEqualTo(3)
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class AndroidRunCommandTest {
assertThat(cmd.async).isNull()
assertThat(cmd.project).isNull()
assertThat(cmd.resultsHistoryName).isNull()
assertThat(cmd.testShards).isNull()
assertThat(cmd.maxTestShards).isNull()
assertThat(cmd.shardTime).isNull()
assertThat(cmd.repeatTests).isNull()
assertThat(cmd.testTargetsAlwaysRun).isNull()
Expand Down Expand Up @@ -247,11 +247,11 @@ class AndroidRunCommandTest {
// flankYml

@Test
fun testShards_parse() {
fun maxTestShards_parse() {
val cmd = AndroidRunCommand()
CommandLine(cmd).parse("--test-shards=3")

assertThat(cmd.testShards).isEqualTo(3)
assertThat(cmd.maxTestShards).isEqualTo(3)
}

@Test
Expand Down
Loading