From 7ef4b1955d9acdf7ecf83a89698eb7218cf763f4 Mon Sep 17 00:00:00 2001 From: bootstraponline Date: Wed, 10 Oct 2018 21:59:28 -0400 Subject: [PATCH] Fix duplicate tool results history ids (#348) * Fix duplicate tool results history ids * Fix tests --- .../main/kotlin/ftl/gc/GcAndroidTestMatrix.kt | 9 ++----- .../src/main/kotlin/ftl/gc/GcIosTestMatrix.kt | 9 ++----- .../src/main/kotlin/ftl/gc/GcToolResults.kt | 9 ++++++- .../main/kotlin/ftl/run/AndroidTestRunner.kt | 5 +++- .../src/main/kotlin/ftl/run/IosTestRunner.kt | 27 ++++++++++--------- .../kotlin/ftl/gc/GcAndroidTestMatrixTest.kt | 7 ++--- .../test/kotlin/ftl/gc/GcIosTestMatrixTest.kt | 9 ++++--- .../test/kotlin/ftl/gc/GcToolResultsTest.kt | 15 ++++++++--- 8 files changed, 52 insertions(+), 38 deletions(-) diff --git a/test_runner/src/main/kotlin/ftl/gc/GcAndroidTestMatrix.kt b/test_runner/src/main/kotlin/ftl/gc/GcAndroidTestMatrix.kt index 47e1ff66fe..d0146865ab 100644 --- a/test_runner/src/main/kotlin/ftl/gc/GcAndroidTestMatrix.kt +++ b/test_runner/src/main/kotlin/ftl/gc/GcAndroidTestMatrix.kt @@ -36,7 +36,8 @@ object GcAndroidTestMatrix { androidDeviceList: AndroidDeviceList, testShardsIndex: Int = -1, config: AndroidArgs, - shardCounter: ShardCounter + shardCounter: ShardCounter, + toolResultsHistory: ToolResultsHistory ): Testing.Projects.TestMatrices.Create { validateTestShardIndex(testShardsIndex, config) @@ -82,12 +83,6 @@ object GcAndroidTestMatrix { .setTestTimeout("${testTimeoutSeconds}s") .setTestSetup(testSetup) - val historyId = GcToolResults.getHistoryId(config) - - val toolResultsHistory = ToolResultsHistory() - .setHistoryId(historyId) - .setProjectId(config.projectId) - val resultsStorage = ResultStorage() .setGoogleCloudStorage(GoogleCloudStorage().setGcsPath(matrixGcsPath)) .setToolResultsHistory(toolResultsHistory) diff --git a/test_runner/src/main/kotlin/ftl/gc/GcIosTestMatrix.kt b/test_runner/src/main/kotlin/ftl/gc/GcIosTestMatrix.kt index 6874cdc189..1eaaf80f6a 100644 --- a/test_runner/src/main/kotlin/ftl/gc/GcIosTestMatrix.kt +++ b/test_runner/src/main/kotlin/ftl/gc/GcIosTestMatrix.kt @@ -30,7 +30,8 @@ object GcIosTestMatrix { testShardsIndex: Int, xcTestParsed: NSDictionary, config: IosArgs, - shardCounter: ShardCounter + shardCounter: ShardCounter, + toolResultsHistory: ToolResultsHistory ): Testing.Projects.TestMatrices.Create { validateTestShardIndex(testShardsIndex, config) val clientInfo = ClientInfo().setName("Flank") @@ -59,12 +60,6 @@ object GcIosTestMatrix { .setIosTestSetup(iOSTestSetup) .setIosXcTest(iOSXCTest) - val historyId = GcToolResults.getHistoryId(config) - - val toolResultsHistory = ToolResultsHistory() - .setHistoryId(historyId) - .setProjectId(config.projectId) - val resultStorage = ResultStorage() .setGoogleCloudStorage(GoogleCloudStorage().setGcsPath(matrixGcsPath)) .setToolResultsHistory(toolResultsHistory) diff --git a/test_runner/src/main/kotlin/ftl/gc/GcToolResults.kt b/test_runner/src/main/kotlin/ftl/gc/GcToolResults.kt index 8ccc548ad8..8ace229f7e 100644 --- a/test_runner/src/main/kotlin/ftl/gc/GcToolResults.kt +++ b/test_runner/src/main/kotlin/ftl/gc/GcToolResults.kt @@ -1,5 +1,6 @@ package ftl.gc +import com.google.api.services.testing.model.ToolResultsHistory import com.google.api.services.testing.model.ToolResultsStep import com.google.api.services.toolresults.ToolResults import com.google.api.services.toolresults.model.History @@ -45,7 +46,13 @@ object GcToolResults { .execute() } - fun getHistoryId(args: IArgs): String? { + fun createToolResultsHistory(args: IArgs): ToolResultsHistory { + return ToolResultsHistory() + .setHistoryId(createHistoryId(args)) + .setProjectId(args.projectId) + } + + private fun createHistoryId(args: IArgs): String? { if (args.resultsHistoryName == null) return null val histories = listHistoriesByName(args) if (histories.isNotEmpty()) return histories.first().historyId diff --git a/test_runner/src/main/kotlin/ftl/run/AndroidTestRunner.kt b/test_runner/src/main/kotlin/ftl/run/AndroidTestRunner.kt index cfd88f0af2..58c3c02240 100644 --- a/test_runner/src/main/kotlin/ftl/run/AndroidTestRunner.kt +++ b/test_runner/src/main/kotlin/ftl/run/AndroidTestRunner.kt @@ -6,6 +6,7 @@ import ftl.config.FtlConstants import ftl.gc.GcAndroidDevice import ftl.gc.GcAndroidTestMatrix import ftl.gc.GcStorage +import ftl.gc.GcToolResults import ftl.json.MatrixMap import ftl.util.ShardCounter import kotlinx.coroutines.experimental.Deferred @@ -25,6 +26,7 @@ object AndroidTestRunner { val runCount = androidArgs.repeatTests val deviceCount = androidArgs.testShardChunks.size val shardCounter = ShardCounter() + val history = GcToolResults.createToolResultsHistory(androidArgs) println(GenericTestRunner.beforeRunMessage(androidArgs)) repeat(runCount) { @@ -37,7 +39,8 @@ object AndroidTestRunner { androidDeviceList = androidDeviceList, testShardsIndex = testShardsIndex, config = androidArgs, - shardCounter = shardCounter + shardCounter = shardCounter, + toolResultsHistory = history ).execute() } } diff --git a/test_runner/src/main/kotlin/ftl/run/IosTestRunner.kt b/test_runner/src/main/kotlin/ftl/run/IosTestRunner.kt index 962df8ce4c..ca71bebbf0 100644 --- a/test_runner/src/main/kotlin/ftl/run/IosTestRunner.kt +++ b/test_runner/src/main/kotlin/ftl/run/IosTestRunner.kt @@ -6,6 +6,7 @@ import ftl.config.FtlConstants import ftl.gc.GcIosMatrix import ftl.gc.GcIosTestMatrix import ftl.gc.GcStorage +import ftl.gc.GcToolResults import ftl.ios.Xctestrun import ftl.json.MatrixMap import ftl.run.GenericTestRunner.beforeRunMessage @@ -17,25 +18,26 @@ object IosTestRunner { // https://github.com/bootstraponline/gcloud_cli/blob/5bcba57e825fc98e690281cf69484b7ba4eb668a/google-cloud-sdk/lib/googlecloudsdk/api_lib/firebase/test/ios/matrix_creator.py#L109 // https://cloud.google.com/sdk/gcloud/reference/alpha/firebase/test/ios/run // https://cloud.google.com/sdk/gcloud/reference/alpha/firebase/test/ios/ - suspend fun runTests(yamlConfig: IosArgs): MatrixMap { + suspend fun runTests(iosArgs: IosArgs): MatrixMap { val (stopwatch, runGcsPath) = GenericTestRunner.beforeRunTests() - val xcTestGcsPath = if (yamlConfig.xctestrunZip.startsWith(FtlConstants.GCS_PREFIX)) { - yamlConfig.xctestrunZip + val xcTestGcsPath = if (iosArgs.xctestrunZip.startsWith(FtlConstants.GCS_PREFIX)) { + iosArgs.xctestrunZip } else { - GcStorage.uploadXCTestZip(yamlConfig, runGcsPath) + GcStorage.uploadXCTestZip(iosArgs, runGcsPath) } - val iosDeviceList = GcIosMatrix.build(yamlConfig.devices) + val iosDeviceList = GcIosMatrix.build(iosArgs.devices) - val xcTestParsed = Xctestrun.parse(yamlConfig.xctestrunFile) + val xcTestParsed = Xctestrun.parse(iosArgs.xctestrunFile) val jobs = arrayListOf>() - val runCount = yamlConfig.repeatTests - val deviceCount = yamlConfig.testShardChunks.size + val runCount = iosArgs.repeatTests + val deviceCount = iosArgs.testShardChunks.size val shardCounter = ShardCounter() + val history = GcToolResults.createToolResultsHistory(iosArgs) - println(beforeRunMessage(yamlConfig)) + println(beforeRunMessage(iosArgs)) repeat(runCount) { repeat(deviceCount) { testShardsIndex -> jobs += async { @@ -45,13 +47,14 @@ object IosTestRunner { runGcsPath = runGcsPath, testShardsIndex = testShardsIndex, xcTestParsed = xcTestParsed, - config = yamlConfig, - shardCounter = shardCounter + config = iosArgs, + shardCounter = shardCounter, + toolResultsHistory = history ).execute() } } } - return GenericTestRunner.afterRunTests(jobs, runGcsPath, stopwatch, yamlConfig) + return GenericTestRunner.afterRunTests(jobs, runGcsPath, stopwatch, iosArgs) } } diff --git a/test_runner/src/test/kotlin/ftl/gc/GcAndroidTestMatrixTest.kt b/test_runner/src/test/kotlin/ftl/gc/GcAndroidTestMatrixTest.kt index 67faa798a1..eb228e0747 100644 --- a/test_runner/src/test/kotlin/ftl/gc/GcAndroidTestMatrixTest.kt +++ b/test_runner/src/test/kotlin/ftl/gc/GcAndroidTestMatrixTest.kt @@ -2,6 +2,7 @@ package ftl.gc import com.google.api.services.testing.model.AndroidDeviceList import ftl.args.AndroidArgs +import ftl.gc.GcToolResults.createToolResultsHistory import ftl.test.util.FlankTestRunner import ftl.util.ShardCounter import org.junit.Test @@ -17,7 +18,7 @@ class GcAndroidTestMatrixTest { val androidArgs = mock(AndroidArgs::class.java) GcAndroidTestMatrix.build( "", "", "", - AndroidDeviceList(), -2, androidArgs, ShardCounter() + AndroidDeviceList(), -2, androidArgs, ShardCounter(), createToolResultsHistory(androidArgs) ) } @@ -26,7 +27,7 @@ class GcAndroidTestMatrixTest { val androidArgs = mock(AndroidArgs::class.java) GcAndroidTestMatrix.build( "", "", "", - AndroidDeviceList(), 1, androidArgs, ShardCounter() + AndroidDeviceList(), 1, androidArgs, ShardCounter(), createToolResultsHistory(androidArgs) ) } @@ -40,7 +41,7 @@ class GcAndroidTestMatrixTest { GcAndroidTestMatrix.build( "", "", "", - AndroidDeviceList(), 0, androidArgs, ShardCounter() + AndroidDeviceList(), 0, androidArgs, ShardCounter(), createToolResultsHistory(androidArgs) ) } } diff --git a/test_runner/src/test/kotlin/ftl/gc/GcIosTestMatrixTest.kt b/test_runner/src/test/kotlin/ftl/gc/GcIosTestMatrixTest.kt index a0a7349785..9fd35086a0 100644 --- a/test_runner/src/test/kotlin/ftl/gc/GcIosTestMatrixTest.kt +++ b/test_runner/src/test/kotlin/ftl/gc/GcIosTestMatrixTest.kt @@ -18,7 +18,8 @@ class GcIosTestMatrixTest { val iosArgs = mock(IosArgs::class.java) `when`(iosArgs.testShardChunks).thenReturn(listOf(listOf(""))) GcIosTestMatrix.build( - IosDeviceList(), "", "", -1, NSDictionary(), iosArgs, ShardCounter() + IosDeviceList(), "", "", -1, NSDictionary(), iosArgs, ShardCounter(), + GcToolResults.createToolResultsHistory(iosArgs) ) } @@ -26,7 +27,8 @@ class GcIosTestMatrixTest { fun build_invalidShardErrors() { val iosArgs = mock(IosArgs::class.java) GcIosTestMatrix.build( - IosDeviceList(), "", "", 1, NSDictionary(), iosArgs, ShardCounter() + IosDeviceList(), "", "", 1, NSDictionary(), iosArgs, ShardCounter(), + GcToolResults.createToolResultsHistory(iosArgs) ) } @@ -40,7 +42,8 @@ class GcIosTestMatrixTest { `when`(iosArgs.xctestrunFile).thenReturn("456") GcIosTestMatrix.build( - IosDeviceList(), "", "", 0, NSDictionary(), iosArgs, ShardCounter() + IosDeviceList(), "", "", 0, NSDictionary(), iosArgs, ShardCounter(), + GcToolResults.createToolResultsHistory(iosArgs) ) } } diff --git a/test_runner/src/test/kotlin/ftl/gc/GcToolResultsTest.kt b/test_runner/src/test/kotlin/ftl/gc/GcToolResultsTest.kt index 86d7c3dd39..87add6e37c 100644 --- a/test_runner/src/test/kotlin/ftl/gc/GcToolResultsTest.kt +++ b/test_runner/src/test/kotlin/ftl/gc/GcToolResultsTest.kt @@ -1,5 +1,6 @@ package ftl.gc +import com.google.api.services.testing.model.ToolResultsHistory import com.google.common.truth.Truth.assertThat import ftl.args.AndroidArgs import ftl.test.util.FlankTestRunner @@ -12,19 +13,25 @@ import org.mockito.Mockito.mock class GcToolResultsTest { @Test - fun getHistoryId_null_succeeds() { + fun createToolResultsHistory_null_succeeds() { val args = mock(AndroidArgs::class.java) `when`(args.projectId).thenReturn("123") - assertThat(GcToolResults.getHistoryId(args)).isNull() + val expected = ToolResultsHistory().setProjectId("123") + + assertThat(GcToolResults.createToolResultsHistory(args)).isEqualTo(expected) } @Test - fun getHistoryId_succeeds() { + fun createToolResultsHistory_succeeds() { val args = mock(AndroidArgs::class.java) `when`(args.projectId).thenReturn("123") `when`(args.resultsHistoryName).thenReturn("custom history") - assertThat(GcToolResults.getHistoryId(args)).isEqualTo("mockId") + val expected = ToolResultsHistory() + .setProjectId("123") + .setHistoryId("mockId") + + assertThat(GcToolResults.createToolResultsHistory(args)).isEqualTo(expected) } }