From 4b7e8383966be38251218038311f0ed2e171b5c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Janek=20G=C3=B3ral?= Date: Tue, 7 Apr 2020 14:21:22 +0200 Subject: [PATCH 1/2] Fix shards calculation when there are ignored tests and shardTime is -1 --- .../src/main/kotlin/ftl/shard/Shard.kt | 7 ++++++- .../src/test/kotlin/ftl/shard/ShardTest.kt | 21 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/test_runner/src/main/kotlin/ftl/shard/Shard.kt b/test_runner/src/main/kotlin/ftl/shard/Shard.kt index 2101fb3f41..45c9ce1953 100644 --- a/test_runner/src/main/kotlin/ftl/shard/Shard.kt +++ b/test_runner/src/main/kotlin/ftl/shard/Shard.kt @@ -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 diff --git a/test_runner/src/test/kotlin/ftl/shard/ShardTest.kt b/test_runner/src/test/kotlin/ftl/shard/ShardTest.kt index d5f92122e0..f19de7b6a8 100644 --- a/test_runner/src/test/kotlin/ftl/shard/ShardTest.kt +++ b/test_runner/src/test/kotlin/ftl/shard/ShardTest.kt @@ -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() + 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) } From 1ead0e608f6657527d7a631a94ec44d4a58450ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Janek=20G=C3=B3ral?= Date: Tue, 7 Apr 2020 14:28:36 +0200 Subject: [PATCH 2/2] Update release_notes.md --- release_notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/release_notes.md b/release_notes.md index 6cf2036011..47abcedfc4 100644 --- a/release_notes.md +++ b/release_notes.md @@ -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))