diff --git a/test_runner/src/main/kotlin/ftl/reports/util/ReportManager.kt b/test_runner/src/main/kotlin/ftl/reports/util/ReportManager.kt index 847ffea302..15f8719c7b 100644 --- a/test_runner/src/main/kotlin/ftl/reports/util/ReportManager.kt +++ b/test_runner/src/main/kotlin/ftl/reports/util/ReportManager.kt @@ -41,7 +41,7 @@ object ReportManager { val objName = matrices.runPath // 2019-03-22_17-20-53.594000_ftrh // shard location in path changes based on iOS or Android. - val matchResult = Regex("/(shard_\\d+)(-rerun_\\d+)?/").find(xmlFile.toString()) + val matchResult = Regex("/.*(shard_\\d+)(-rerun_\\d+)?/").find(xmlFile.toString()) val shardName = matchResult?.value?.removePrefix("/")?.removeSuffix("/") // shard_0 || shard_0-rerun_1 val matrixPath = Paths.get(objName, shardName).toString() // 2019-03-22_17-20-53.594000_ftrh/shard_0 diff --git a/test_runner/src/main/kotlin/ftl/run/common/FetchArtifacts.kt b/test_runner/src/main/kotlin/ftl/run/common/FetchArtifacts.kt index 267ed59676..f9dc80e3f8 100644 --- a/test_runner/src/main/kotlin/ftl/run/common/FetchArtifacts.kt +++ b/test_runner/src/main/kotlin/ftl/run/common/FetchArtifacts.kt @@ -1,20 +1,18 @@ package ftl.run.common import com.google.cloud.storage.Storage -import ftl.args.AndroidArgs import ftl.args.IArgs import ftl.config.FtlConstants -import ftl.gc.GcStorage import ftl.json.MatrixMap +import ftl.gc.GcStorage import ftl.util.Artifacts import ftl.util.MatrixState -import ftl.util.ObjPath +import java.nio.file.Path +import java.nio.file.Paths import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.joinAll import kotlinx.coroutines.launch -import java.nio.file.Path -import java.nio.file.Paths internal suspend fun fetchArtifacts(matrixMap: MatrixMap, args: IArgs) = coroutineScope { println("FetchArtifacts") @@ -64,18 +62,13 @@ internal suspend fun fetchArtifacts(matrixMap: MatrixMap, args: IArgs) = corouti internal fun getDownloadPath(args: IArgs, blobPath: String): Path { val localDir = args.localResultDir - val p = if (args is AndroidArgs) - ObjPath.parse(blobPath) else - ObjPath.legacyParse(blobPath) + val parsed = Paths.get(blobPath) + val objName = if (args.useLocalResultDir()) "" else parsed.getName(0).toString() + // for iOS it is shardName, remove this comment after FTL introduce server side sharding for iOS + val matrixName = parsed.getName(1).toString() + val deviceName = parsed.getName(2).toString() + val filePathName = if (parsed.nameCount > 4 && args.keepFilePath) parsed.parent.drop(3).joinToString("/") else "" + val fileName = parsed.fileName.toString() - // Store downloaded artifacts at device root. - return Paths.get( - localDir, - if (args.useLocalResultDir().not()) p.objName else "", - p.matrixName, - p.shardName, - p.deviceName, - if (args.keepFilePath) p.filePathName else "", - p.fileName - ) + return Paths.get("$localDir/$objName/$matrixName/$deviceName/$filePathName/$fileName") } diff --git a/test_runner/src/main/kotlin/ftl/util/ObjPath.kt b/test_runner/src/main/kotlin/ftl/util/ObjPath.kt deleted file mode 100644 index 211465723c..0000000000 --- a/test_runner/src/main/kotlin/ftl/util/ObjPath.kt +++ /dev/null @@ -1,59 +0,0 @@ -package ftl.util - -import java.nio.file.Paths - -data class ObjPath( - val fileName: String, - val objName: String, - val shardName: String, - val deviceName: String, - val filePathName: String, - val matrixName: String -) { - companion object { - fun parse(path: String): ObjPath { - val parsed = Paths.get(path) - - val fileName = parsed.fileName.toString() - val objName = parsed.getName(0).toString() - val matrixName = parsed.getName(1).toString() - val (deviceName, shardNumber) = parsed.getName(2).toString().split("-shard_").run { - first() to getOrElse(1) { "0" } - } - val shardName = "shard_$shardNumber" - val filePathName = if (parsed.nameCount > 4) { - parsed.parent.drop(3).joinToString("/") - } else { "" } - - return ObjPath( - fileName = fileName, - objName = objName, - shardName = shardName, - deviceName = deviceName, - filePathName = filePathName, - matrixName = matrixName - ) - } - - fun legacyParse(path: String): ObjPath { - val parsed = Paths.get(path) - - val fileName = parsed.fileName.toString() - val objName = parsed.getName(0).toString() - val shardName = parsed.getName(1).toString() - val deviceName = parsed.getName(2).toString() - val filePathName = if (parsed.nameCount > 4) { - parsed.parent.drop(3).joinToString("/") - } else { "" } - - return ObjPath( - fileName = fileName, - objName = objName, - shardName = shardName, - deviceName = deviceName, - filePathName = filePathName, - matrixName = "" - ) - } - } -} diff --git a/test_runner/src/test/kotlin/ftl/run/TestRunnerTest.kt b/test_runner/src/test/kotlin/ftl/run/TestRunnerTest.kt index 8526a49824..65e0770d3e 100644 --- a/test_runner/src/test/kotlin/ftl/run/TestRunnerTest.kt +++ b/test_runner/src/test/kotlin/ftl/run/TestRunnerTest.kt @@ -12,7 +12,6 @@ import ftl.config.FtlConstants.isWindows import ftl.http.executeWithRetry import ftl.run.common.getDownloadPath import ftl.test.util.FlankTestRunner -import ftl.util.ObjPath import io.mockk.every import io.mockk.mockk import io.mockk.mockkStatic @@ -29,14 +28,19 @@ import org.junit.Test import org.junit.contrib.java.lang.system.SystemOutRule import org.junit.runner.RunWith +private const val OBJECT_NAME = "2019-03-22_15-30-02.189000_frjt" +private const val FILE_NAME = "StandardOutputAndStandardError.txt" +private const val SHARD = "shard_0" +private const val MATRIX = "matrix_1" +private const val ANDROID_DEVICE = "NexusLowRes-27-en-portrait-shard_0-rerun_1" +private const val IOS_DEVICE = "iphone8-12.0-en-portrait" +private const val LOCAL_DIR = "results" +private const val TEST_FILE_PATH = "any/path/that/is/possible" +private const val FULL_IOS_PATH = "$OBJECT_NAME/$SHARD/$IOS_DEVICE/$TEST_FILE_PATH/$FILE_NAME" +private const val FULL_ANDROID_PATH = "$OBJECT_NAME/$MATRIX/$ANDROID_DEVICE/$TEST_FILE_PATH/$FILE_NAME" + @RunWith(FlankTestRunner::class) class TestRunnerTest { - - private val gcsIosPath = - "2019-03-22_15-30-02.189000_frjt/shard_0/iphone8-12.0-en-portrait/TestLogs/Test-Transient Testing-2019.03.22_08-29-41--0700.xcresult/1_Test/Diagnostics/EarlGreyExampleSwiftTests-C6803D8C-4BDB-4C84-8945-9AC64056FBA4/EarlGreyExampleSwiftTests-EDBFF942-A88A-46A5-87CA-A1E29555C2CA/StandardOutputAndStandardError.txt" - private val gcsAndroidPath = - "2019-03-22_15-30-02.189000_frjt/matrix_1/iphone8-12.0-en-portrait-shard_0/StandardOutputAndStandardError.txt" - private val localResultDir = "results" private val iosArgs = mockk() private val androidArgs = mockk() @@ -48,125 +52,62 @@ class TestRunnerTest { @Test fun `Verify getDownloadPath localResultDir false and keepFilePath false - ios`() { - val parsed = ObjPath.legacyParse(gcsIosPath) - - every { iosArgs.localResultDir } returns localResultDir + every { iosArgs.localResultDir } returns LOCAL_DIR every { iosArgs.useLocalResultDir() } returns false every { iosArgs.keepFilePath } returns false - val downloadFile = getDownloadPath(iosArgs, gcsIosPath) - assertThat(downloadFile).isEqualTo( - Paths.get( - localResultDir, - parsed.objName, - parsed.shardName, - parsed.deviceName, - parsed.fileName - ) - ) + val downloadFile = getDownloadPath(iosArgs, FULL_IOS_PATH) + assertThat(downloadFile).isEqualTo(Paths.get("$LOCAL_DIR/$OBJECT_NAME/$SHARD/$IOS_DEVICE/$FILE_NAME")) } @Test fun `Verify getDownloadPath localResultDir false and keepFilePath true - ios`() { - val parsed = ObjPath.legacyParse(gcsIosPath) - - every { iosArgs.localResultDir } returns localResultDir + every { iosArgs.localResultDir } returns LOCAL_DIR every { iosArgs.useLocalResultDir() } returns false every { iosArgs.keepFilePath } returns true - val downloadFile = getDownloadPath(iosArgs, gcsIosPath) - assertThat(downloadFile).isEqualTo( - Paths.get( - localResultDir, - parsed.objName, - parsed.shardName, - parsed.deviceName, - parsed.filePathName, - parsed.fileName - ) - ) + val downloadFile = getDownloadPath(iosArgs, FULL_IOS_PATH) + assertThat(downloadFile).isEqualTo(Paths.get("$LOCAL_DIR/$FULL_IOS_PATH")) } @Test fun `Verify getDownloadPath localResultDir true and keepFilePath false - ios`() { - val parsed = ObjPath.legacyParse(gcsIosPath) - - every { iosArgs.localResultDir } returns localResultDir + every { iosArgs.localResultDir } returns LOCAL_DIR every { iosArgs.useLocalResultDir() } returns true every { iosArgs.keepFilePath } returns false - val downloadFile = getDownloadPath(iosArgs, gcsIosPath) - assertThat(downloadFile).isEqualTo( - Paths.get( - localResultDir, - parsed.shardName, - parsed.deviceName, - parsed.fileName - ) - ) + val downloadFile = getDownloadPath(iosArgs, FULL_IOS_PATH) + assertThat(downloadFile).isEqualTo(Paths.get("$LOCAL_DIR/$SHARD/$IOS_DEVICE/$FILE_NAME")) } @Test fun `Verify getDownloadPath localResultDir true and keepFilePath true - ios`() { - val parsed = ObjPath.legacyParse(gcsIosPath) - - every { iosArgs.localResultDir } returns localResultDir + every { iosArgs.localResultDir } returns LOCAL_DIR every { iosArgs.useLocalResultDir() } returns true every { iosArgs.keepFilePath } returns true - val downloadFile = getDownloadPath(iosArgs, gcsIosPath) - assertThat(downloadFile).isEqualTo( - Paths.get( - localResultDir, - parsed.shardName, - parsed.deviceName, - parsed.filePathName, - parsed.fileName - ) - ) + val downloadFile = getDownloadPath(iosArgs, FULL_IOS_PATH) + assertThat(downloadFile).isEqualTo(Paths.get("$LOCAL_DIR/$SHARD/$IOS_DEVICE/$TEST_FILE_PATH/$FILE_NAME")) } @Test fun `Verify getDownloadPath localResultDir true and keepFilePath true - android`() { - val parsed = ObjPath.parse(gcsAndroidPath) - - every { androidArgs.localResultDir } returns localResultDir + every { androidArgs.localResultDir } returns LOCAL_DIR every { androidArgs.useLocalResultDir() } returns true every { androidArgs.keepFilePath } returns true - val downloadFile = getDownloadPath(androidArgs, gcsAndroidPath) - assertThat(downloadFile).isEqualTo( - Paths.get( - localResultDir, - parsed.matrixName, - parsed.shardName, - parsed.deviceName, - parsed.filePathName, - parsed.fileName - ) - ) + val downloadFile = getDownloadPath(androidArgs, FULL_ANDROID_PATH) + assertThat(downloadFile).isEqualTo(Paths.get("$LOCAL_DIR/$MATRIX/$ANDROID_DEVICE/$TEST_FILE_PATH/$FILE_NAME")) } @Test fun `Verify getDownloadPath localResultDir false and keepFilePath true`() { - val parsed = ObjPath.parse(gcsAndroidPath) - - every { androidArgs.localResultDir } returns localResultDir + every { androidArgs.localResultDir } returns LOCAL_DIR every { androidArgs.useLocalResultDir() } returns false every { androidArgs.keepFilePath } returns true - val downloadFile = getDownloadPath(androidArgs, gcsAndroidPath) - assertThat(downloadFile).isEqualTo( - Paths.get( - localResultDir, - parsed.objName, - parsed.matrixName, - parsed.shardName, - parsed.deviceName, - parsed.filePathName, - parsed.fileName - ) - ) + val downloadFile = getDownloadPath(androidArgs, FULL_ANDROID_PATH) + assertThat(downloadFile).isEqualTo(Paths.get("$LOCAL_DIR/$FULL_ANDROID_PATH")) } @Test diff --git a/test_runner/src/test/kotlin/ftl/util/ObjPathTest.kt b/test_runner/src/test/kotlin/ftl/util/ObjPathTest.kt deleted file mode 100644 index cc00575b68..0000000000 --- a/test_runner/src/test/kotlin/ftl/util/ObjPathTest.kt +++ /dev/null @@ -1,32 +0,0 @@ -package ftl.util - -import com.google.common.truth.Truth.assertThat -import org.junit.Test - -class ObjPathTest { - - @Test - fun parse() { - val path = "2019-03-22_15-39-20.400000_ESdl/matrix_1/NexusLowRes-28-en-portrait-shard_0/com/package/name/b.txt" - val parsed = ObjPath.parse(path) - - assertThat(parsed.objName).isEqualTo("2019-03-22_15-39-20.400000_ESdl") - assertThat(parsed.fileName).isEqualTo("b.txt") - assertThat(parsed.shardName).isEqualTo("shard_0") - assertThat(parsed.deviceName).isEqualTo("NexusLowRes-28-en-portrait") - assertThat(parsed.filePathName).isEqualTo("com/package/name") - assertThat(parsed.matrixName).isEqualTo("matrix_1") - } - - @Test - fun legacyParse() { - val path = "2019-03-22_15-39-20.400000_ESdl/shard_0/NexusLowRes-28-en-portrait/com/package/name/b.txt" - val parsed = ObjPath.legacyParse(path) - - assertThat(parsed.objName).isEqualTo("2019-03-22_15-39-20.400000_ESdl") - assertThat(parsed.fileName).isEqualTo("b.txt") - assertThat(parsed.shardName).isEqualTo("shard_0") - assertThat(parsed.deviceName).isEqualTo("NexusLowRes-28-en-portrait") - assertThat(parsed.filePathName).isEqualTo("com/package/name") - } -}