Skip to content

Commit df4b13e

Browse files
authored
Updating result storage path (#73)
* Updating result storage path * linting * addressing feedback * linting * renaming method * adding test
1 parent 336fedc commit df4b13e

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

AndroidXCI/lib/src/main/kotlin/dev/androidx/ci/testRunner/TestMatrixStore.kt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package dev.androidx.ci.testRunner
1818

19+
import com.google.common.annotations.VisibleForTesting
1920
import dev.androidx.ci.datastore.DatastoreApi
2021
import dev.androidx.ci.firebase.FirebaseTestLabApi
2122
import dev.androidx.ci.firebase.ToolsResultApi
@@ -299,7 +300,7 @@ internal class TestMatrixStore(
299300
)
300301
val resultStorage = ResultStorage(
301302
googleCloudStorage = GoogleCloudStorage(
302-
gcsPath = testRunKey.resultGcsPath().path
303+
gcsPath = createUniqueResultGcsPath(testRunKey).path
303304
),
304305
toolResultsHistory = ToolResultsHistory(
305306
projectId = firebaseProjectId,
@@ -337,7 +338,7 @@ internal class TestMatrixStore(
337338

338339
val resultStorage = ResultStorage(
339340
googleCloudStorage = GoogleCloudStorage(
340-
gcsPath = testRunKey.resultGcsPath().path
341+
gcsPath = createUniqueResultGcsPath(testRunKey).path
341342
),
342343
toolResultsHistory = testMatrix.resultStorage.toolResultsHistory
343344
)
@@ -375,5 +376,8 @@ internal class TestMatrixStore(
375376
)
376377
}
377378

378-
private fun TestRun.Id.resultGcsPath() = (resultsGcsPrefix + key.name)
379+
@VisibleForTesting
380+
internal fun createUniqueResultGcsPath(testRunKey: TestRun.Id): GcsPath {
381+
return resultsGcsPrefix + testRunKey.key.name + UUID.randomUUID().toString()
382+
}
379383
}

AndroidXCI/lib/src/test/kotlin/dev/androidx/ci/testRunner/TestMatrixStoreTest.kt

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,17 @@ import dev.androidx.ci.generated.ftl.FileReference
3030
import dev.androidx.ci.generated.ftl.ShardingOption
3131
import dev.androidx.ci.generated.ftl.TestMatrix
3232
import dev.androidx.ci.generated.ftl.UniformSharding
33+
import dev.androidx.ci.testRunner.dto.TestRun
3334
import dev.androidx.ci.testRunner.vo.ApkInfo
3435
import dev.androidx.ci.testRunner.vo.DeviceSetup
3536
import dev.androidx.ci.testRunner.vo.UploadedApk
3637
import kotlinx.coroutines.runBlocking
3738
import org.junit.Test
3839

3940
internal class TestMatrixStoreTest {
40-
val firebaseTestLabApi = FakeFirebaseTestLabApi()
41-
val datastoreApi = FakeDatastore()
42-
val toolsResultApi = FakeToolsResultApi()
41+
private val firebaseTestLabApi = FakeFirebaseTestLabApi()
42+
private val datastoreApi = FakeDatastore()
43+
private val toolsResultApi = FakeToolsResultApi()
4344
private val store = TestMatrixStore(
4445
firebaseProjectId = "p1",
4546
firebaseTestLabApi = firebaseTestLabApi,
@@ -329,6 +330,28 @@ internal class TestMatrixStoreTest {
329330
).containsExactly("/sdcard/Android/data/$testPackageName/cache/androidx_screenshots")
330331
}
331332
}
333+
334+
@Test
335+
fun createUniqueResultGcsPath() = runBlocking {
336+
val testRunId = TestRun.createId(
337+
datastoreApi = datastoreApi,
338+
environment = envMatrix1,
339+
clientInfo = ClientInfo(name = "test"),
340+
sharding = ShardingOption(),
341+
appApk = createFakeApk("app.pak").apkInfo,
342+
testApk = createFakeApk("test.apk").apkInfo,
343+
deviceSetup = DeviceSetup()
344+
)
345+
346+
val resultGcsPath1 = store.createUniqueResultGcsPath(testRunId)
347+
val resultGcsPath2 = store.createUniqueResultGcsPath(testRunId)
348+
349+
assertThat(
350+
resultGcsPath1
351+
).isNotEqualTo(
352+
resultGcsPath2
353+
)
354+
}
332355
private fun createFakeApk(name: String) = UploadedApk(
333356
gcsPath = GcsPath("gs://foo/bar/$name"),
334357
apkInfo = ApkInfo(

0 commit comments

Comments
 (0)