Skip to content

Commit

Permalink
Refractor magic number
Browse files Browse the repository at this point in the history
Set 1..50 range to use
AVAILABLE_SHARD_COUNT_RANGE
to avoid test fails on incerase range
  • Loading branch information
adamfilipow92 committed Jun 1, 2020
1 parent d27525e commit 3c78771
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 10 deletions.
5 changes: 3 additions & 2 deletions test_runner/src/main/kotlin/ftl/args/ArgsHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.google.cloud.storage.BucketInfo
import com.google.cloud.storage.Storage
import com.google.cloud.storage.StorageClass
import com.google.cloud.storage.StorageOptions
import ftl.args.IArgs.Companion.AVAILABLE_SHARD_COUNT_RANGE
import ftl.args.yml.IYmlMap
import ftl.args.yml.YamlObjectMapper
import ftl.config.FtlConstants
Expand Down Expand Up @@ -64,8 +65,8 @@ object ArgsHelper {
" See https://github.com/GoogleCloudPlatform/google-cloud-java#specifying-a-project-id"
)

if (args.maxTestShards !in IArgs.AVAILABLE_SHARD_COUNT_RANGE && args.maxTestShards != -1)
throw FlankFatalError("max-test-shards must be >= 1 and <= 50, or -1. But current is ${args.maxTestShards}")
if (args.maxTestShards !in AVAILABLE_SHARD_COUNT_RANGE && args.maxTestShards != -1)
throw FlankFatalError("max-test-shards must be >= ${AVAILABLE_SHARD_COUNT_RANGE.first} and <= ${AVAILABLE_SHARD_COUNT_RANGE.last}, or -1. But current is ${args.maxTestShards}")

if (args.shardTime <= 0 && args.shardTime != -1) throw FlankFatalError("shard-time must be >= 1 or -1")
if (args.repeatTests < 1) throw FlankFatalError("num-test-runs must be >= 1")
Expand Down
8 changes: 4 additions & 4 deletions test_runner/src/test/kotlin/ftl/args/AndroidArgsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ AndroidArgs

@Test
fun `cli numUniformShards`() {
val expected = 50
val expected = AVAILABLE_SHARD_COUNT_RANGE.last
val cli = AndroidRunCommand()
CommandLine(cli).parseArgs("--num-uniform-shards=$expected")

Expand All @@ -686,9 +686,9 @@ AndroidArgs
gcloud:
app: $appApk
test: $testApk
num-uniform-shards: 50
num-uniform-shards: ${AVAILABLE_SHARD_COUNT_RANGE.last}
flank:
max-test-shards: 50
max-test-shards: ${AVAILABLE_SHARD_COUNT_RANGE.last}
"""
AndroidArgs.load(yaml)
}
Expand Down Expand Up @@ -1341,7 +1341,7 @@ AndroidArgs
" num-flaky-test-attempts: 3",
"""
flank:
max-test-shards: 50
max-test-shards: ${AVAILABLE_SHARD_COUNT_RANGE.last}
""".trimIndent(),
"""
flank:
Expand Down
2 changes: 1 addition & 1 deletion test_runner/src/test/kotlin/ftl/args/ArgsHelperTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ class ArgsHelperTest {
@Test
fun testInvalidTestShards() {
val maxTestShards = -2
exceptionRule.expectMessage("max-test-shards must be >= 1 and <= 50, or -1. But current is $maxTestShards")
exceptionRule.expectMessage("max-test-shards must be >= ${IArgs.AVAILABLE_SHARD_COUNT_RANGE.first} and <= ${IArgs.AVAILABLE_SHARD_COUNT_RANGE.last}, or -1. But current is $maxTestShards")

val args = spyk(AndroidArgs.default())
every { args.maxTestShards } returns maxTestShards
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ftl.gc.android

import com.google.api.services.testing.model.AndroidInstrumentationTest
import com.google.api.services.testing.model.FileReference
import ftl.args.IArgs
import ftl.args.ShardChunks
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNotNull
Expand Down Expand Up @@ -40,8 +41,7 @@ class UtilsKtTest {
.setupTestTargets(
disableSharding = false,
testShards = testShards,
numUniformShards = 50,
keepTestTargetsEmpty = false
numUniformShards = IArgs.AVAILABLE_SHARD_COUNT_RANGE.last
)

// then
Expand Down
3 changes: 2 additions & 1 deletion test_runner/src/test/kotlin/ftl/shard/ShardTest.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ftl.shard

import com.google.common.truth.Truth.assertThat
import ftl.args.IArgs
import ftl.args.IosArgs
import ftl.reports.xml.model.JUnitTestCase
import ftl.reports.xml.model.JUnitTestResult
Expand Down Expand Up @@ -211,7 +212,7 @@ class ShardTest {
@Test
fun `tests annotated with @Ignore should not produce additional shards`() {
val androidMockedArgs = mockk<IosArgs>()
every { androidMockedArgs.maxTestShards } returns 50
every { androidMockedArgs.maxTestShards } returns IArgs.AVAILABLE_SHARD_COUNT_RANGE.last
every { androidMockedArgs.shardTime } returns -1

val testsToRun = listOf(
Expand Down

0 comments on commit 3c78771

Please sign in to comment.