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

Fix shards calculation when there are ignored tests and shardTime is -1 #704

Merged
merged 2 commits into from
Apr 8, 2020
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
1 change: 1 addition & 0 deletions release_notes.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
## next (unreleased)
- [#704](https://github.com/Flank/flank/pull/704) Fix shards calculation when there are ignored tests and shardTime is -1. ([jan-gogo](https://github.com/jan-gogo))
- [#692](https://github.com/Flank/flank/pull/698) Add support for other-files option. ([jan-gogo](https://github.com/jan-gogo))
- [#695](https://github.com/Flank/flank/pull/695) Add support for additional-apks option. ([jan-gogo](https://github.com/jan-gogo))
- [#683](https://github.com/Flank/flank/pull/683) Print web link. ([pawelpasterz](https://github.com/pawelpasterz))
Expand Down
7 changes: 6 additions & 1 deletion test_runner/src/main/kotlin/ftl/shard/Shard.kt
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,12 @@ object Shard {
// We want to iterate over testcase going from slowest to fastest
.sortedByDescending(TestMethod::time)

val testCount = testCases.size
// Ugly hotfix for case when all test cases are annotated with @Ignore
// we need to filter them because they have time == 0.0 which cause empty shards creation, few lines later
// and we don't need additional shards for ignored tests.
val testCount =
if (testCases.isEmpty()) 0
else testCases.filter { it.time > 0.0 }.takeIf { it.isNotEmpty() }?.size ?: 1

// If maxShards is infinite or we have more shards than tests, let's match it
val shardsCount = if (maxShards == -1 || maxShards > testCount) testCount else maxShards
Expand Down
21 changes: 21 additions & 0 deletions test_runner/src/test/kotlin/ftl/shard/ShardTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,27 @@ class ShardTest {
assertTrue(shards.flatMap { it.testMethods }.map { it.time }.filter { it == 0.0 }.count() == 1)
shards.forEach { assertEquals(10.0, it.time, 0.0) }
}

@Test
fun `tests annotated with @Ignore should not produce additional shards`() {
val androidMockedArgs = mockk<IosArgs>()
every { androidMockedArgs.maxTestShards } returns 50
every { androidMockedArgs.shardTime } returns -1

val testsToRun = listOf(
FlankTestMethod("a/a", ignored = true),
FlankTestMethod("b/b", ignored = true),
FlankTestMethod("c/c", ignored = true)
)

val oldTestResult = newSuite(mutableListOf())

val shardCount = Shard.shardCountByTime(testsToRun, oldTestResult, androidMockedArgs)
assertEquals(-1, shardCount)

val shards = Shard.createShardsByShardCount(testsToRun, oldTestResult, androidMockedArgs, shardCount)
assertEquals(1, shards.size)
}
}

private fun listOfFlankTestMethod(vararg args: String) = listOf(*args).map { FlankTestMethod(it) }