Skip to content

Commit

Permalink
Fix duplicate tool results history ids (#348)
Browse files Browse the repository at this point in the history
* Fix duplicate tool results history ids

* Fix tests
  • Loading branch information
bootstraponline authored Oct 11, 2018
1 parent 7bb7531 commit 7ef4b19
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 38 deletions.
9 changes: 2 additions & 7 deletions test_runner/src/main/kotlin/ftl/gc/GcAndroidTestMatrix.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down
9 changes: 2 additions & 7 deletions test_runner/src/main/kotlin/ftl/gc/GcIosTestMatrix.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand Down
9 changes: 8 additions & 1 deletion test_runner/src/main/kotlin/ftl/gc/GcToolResults.kt
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion test_runner/src/main/kotlin/ftl/run/AndroidTestRunner.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand All @@ -37,7 +39,8 @@ object AndroidTestRunner {
androidDeviceList = androidDeviceList,
testShardsIndex = testShardsIndex,
config = androidArgs,
shardCounter = shardCounter
shardCounter = shardCounter,
toolResultsHistory = history
).execute()
}
}
Expand Down
27 changes: 15 additions & 12 deletions test_runner/src/main/kotlin/ftl/run/IosTestRunner.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<Deferred<TestMatrix>>()
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 {
Expand All @@ -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)
}
}
7 changes: 4 additions & 3 deletions test_runner/src/test/kotlin/ftl/gc/GcAndroidTestMatrixTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -17,7 +18,7 @@ class GcAndroidTestMatrixTest {
val androidArgs = mock(AndroidArgs::class.java)
GcAndroidTestMatrix.build(
"", "", "",
AndroidDeviceList(), -2, androidArgs, ShardCounter()
AndroidDeviceList(), -2, androidArgs, ShardCounter(), createToolResultsHistory(androidArgs)
)
}

Expand All @@ -26,7 +27,7 @@ class GcAndroidTestMatrixTest {
val androidArgs = mock(AndroidArgs::class.java)
GcAndroidTestMatrix.build(
"", "", "",
AndroidDeviceList(), 1, androidArgs, ShardCounter()
AndroidDeviceList(), 1, androidArgs, ShardCounter(), createToolResultsHistory(androidArgs)
)
}

Expand All @@ -40,7 +41,7 @@ class GcAndroidTestMatrixTest {

GcAndroidTestMatrix.build(
"", "", "",
AndroidDeviceList(), 0, androidArgs, ShardCounter()
AndroidDeviceList(), 0, androidArgs, ShardCounter(), createToolResultsHistory(androidArgs)
)
}
}
9 changes: 6 additions & 3 deletions test_runner/src/test/kotlin/ftl/gc/GcIosTestMatrixTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,17 @@ 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)
)
}

@Test(expected = IllegalArgumentException::class)
fun build_invalidShardErrors() {
val iosArgs = mock(IosArgs::class.java)
GcIosTestMatrix.build(
IosDeviceList(), "", "", 1, NSDictionary(), iosArgs, ShardCounter()
IosDeviceList(), "", "", 1, NSDictionary(), iosArgs, ShardCounter(),
GcToolResults.createToolResultsHistory(iosArgs)
)
}

Expand All @@ -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)
)
}
}
15 changes: 11 additions & 4 deletions test_runner/src/test/kotlin/ftl/gc/GcToolResultsTest.kt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
}
}

0 comments on commit 7ef4b19

Please sign in to comment.