Skip to content

Commit

Permalink
Rewrite as --files-to-download
Browse files Browse the repository at this point in the history
  • Loading branch information
bootstraponline committed Jan 9, 2019
1 parent 7a15af2 commit f6e217f
Show file tree
Hide file tree
Showing 23 changed files with 192 additions and 117 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ flank:
# test targets - a list of tests to run. omit to run all tests.
test-targets:
- b/testBasicSelection
# regex is matched against bucket paths, for example: 2019-01-09_00:18:07.314000_hCMY/shard_0/EarlGreyExampleSwiftTests_iphoneos12.1-arm64e.xctestrun
files-to-download:
- .*.png$
```
### Android example
Expand Down Expand Up @@ -127,9 +130,9 @@ flank:
# useful if you need to grant permissions or login before other tests run
test-targets-always-run:
- class com.example.app.ExampleUiTest#testPasses
# directories to download after the test runs from the result bucket
directories-to-download:
- /sdcard/screenshots
# regex is matched against bucket paths, for example: 2019-01-09_00:13:06.106000_YCKl/shard_0/NexusLowRes-28-en-portrait/bugreport.txt
files-to-download:
- .*.mp4$
```

### CI integration
Expand Down
6 changes: 6 additions & 0 deletions contributing.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
## Setup

- Install [Oracle JDK 8](http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html)
- JDK 9 or later will not work
- [IntelliJ Toolbox](https://www.jetbrains.com/toolbox/app/)
Expand All @@ -21,6 +22,11 @@ See the main readme for instructions on how to run the iOS and Android samples.
- Update `IArgs` with new property
- Update `AndroidArgs` to reference the propery and update `toString`
- Update `IosArgs` to reference the propery and `toString`
- Add test to `IosArgsTest`
- Add test to `IosRunCommandTest` and update `empty_params_parse_null` test
- Add test to `AndroidArgsTest`
- Add test to `AndroidRunCommandTest` and update `empty_params_parse_null` test
- Update Android/iOS example config in README.md, `flank.yml` and `flank.ios.yml`

## CLA

Expand Down
1 change: 1 addition & 0 deletions release_notes.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## v4.2.0 (unreleased)

- Fix create Gcs bucket [#444](https://github.com/TestArmada/flank/pull/444)
- Add `directories-to-download` to Android and iOS. Specify a list of regular expressions to download files from the Google Cloud Storage bucket. [#441](https://github.com/TestArmada/flank/pull/441)

## v4.1.1

Expand Down
4 changes: 4 additions & 0 deletions test_runner/flank.ios.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,7 @@ flank:
#
# test-targets:
# - b/testBasicSelection

# # regex is matched against bucket paths, for example: 2019-01-09_00:18:07.314000_hCMY/shard_0/EarlGreyExampleSwiftTests_iphoneos12.1-arm64e.xctestrun
# files-to-download:
# - .*.png$
4 changes: 4 additions & 0 deletions test_runner/flank.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,7 @@ flank:
#
# test-targets-always-run:
# - class com.example.app.ExampleUiTest#testPasses

# # regex is matched against bucket paths, for example: 2019-01-09_00:13:06.106000_YCKl/shard_0/NexusLowRes-28-en-portrait/bugreport.txt
# files-to-download:
# - .*.mp4$
6 changes: 3 additions & 3 deletions test_runner/src/main/kotlin/ftl/args/AndroidArgs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class AndroidArgs(
override val repeatTests = cli?.repeatTests ?: flank.repeatTests
override val smartFlankGcsPath = flank.smartFlankGcsPath
override val testTargetsAlwaysRun = cli?.testTargetsAlwaysRun ?: flank.testTargetsAlwaysRun
val directoriesToDownload = cli?.directoriesToDownload ?: flank.directoriesToDownload
override val filesToDownload = cli?.filesToDownload ?: flank.filesToDownload

// computed properties not specified in yaml
override val testShardChunks: List<List<String>> by lazy {
Expand Down Expand Up @@ -160,8 +160,8 @@ ${devicesToString(devices)}
testShards: $testShards
repeatTests: $repeatTests
smartFlankGcsPath: $smartFlankGcsPath
directories-to-download:
${listToString(directoriesToDownload)}
files-to-download:
${listToString(filesToDownload)}
test-targets-always-run:
${listToString(testTargetsAlwaysRun)}
""".trimIndent()
Expand Down
1 change: 1 addition & 0 deletions test_runner/src/main/kotlin/ftl/args/IArgs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ interface IArgs {
val repeatTests: Int
val smartFlankGcsPath: String
val testTargetsAlwaysRun: List<String>
val filesToDownload: List<String>

// computed property
val testShardChunks: List<List<String>>
Expand Down
3 changes: 3 additions & 0 deletions test_runner/src/main/kotlin/ftl/args/IosArgs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class IosArgs(
override val repeatTests = cli?.repeatTests ?: flank.repeatTests
override val smartFlankGcsPath = flank.smartFlankGcsPath
override val testTargetsAlwaysRun = cli?.testTargetsAlwaysRun ?: flank.testTargetsAlwaysRun
override val filesToDownload = cli?.filesToDownload ?: flank.filesToDownload

private val iosFlank = iosFlankYml.flank
val testTargets = cli?.testTargets ?: iosFlank.testTargets
Expand Down Expand Up @@ -123,6 +124,8 @@ ${devicesToString(devices)}
smartFlankGcsPath: $smartFlankGcsPath
test-targets-always-run:
${listToString(testTargetsAlwaysRun)}
files-to-download:
${listToString(filesToDownload)}
# iOS flank
test-targets:
${listToString(testTargets)}
Expand Down
7 changes: 4 additions & 3 deletions test_runner/src/main/kotlin/ftl/args/yml/FlankYml.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ class FlankYmlParams(

@field:JsonProperty("test-targets-always-run")
val testTargetsAlwaysRun: List<String> = emptyList(),
@field:JsonProperty("directories-to-download")
val directoriesToDownload: List<String> = emptyList()

@field:JsonProperty("files-to-download")
val filesToDownload: List<String> = emptyList()
) {
companion object : IYmlKeys {
override val keys = listOf("testShards", "repeatTests", "smartFlankGcsPath", "test-targets-always-run", "directories-to-download")
override val keys = listOf("testShards", "repeatTests", "smartFlankGcsPath", "test-targets-always-run", "files-to-download")
}

init {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,16 +138,6 @@ class AndroidRunCommand : Runnable {
)
var directoriesToPull: List<String>? = null

@Option(
names = ["--directories-to-download"],
split = ",",
description = ["A list of paths that will be downloaded from the resulting bucket " +
"to the designated local results folder after the test is complete. These must be absolute paths " +
"(for example, --directories-to-download /images/tempDir1,/data/local/tmp/tempDir2). " +
"Path names are restricted to the characters a-zA-Z0-9_-./+."]
)
var directoriesToDownload: List<String>? = null

@Option(
names = ["--device"],
split = ",",
Expand Down Expand Up @@ -245,6 +235,16 @@ class AndroidRunCommand : Runnable {
)
var testTargetsAlwaysRun: List<String>? = null

@Option(
names = ["--files-to-download"],
split = ",",
description = ["A list of paths that will be downloaded from the resulting bucket " +
"to the local results folder after the test is complete. These must be absolute paths " +
"(for example, --files-to-download /images/tempDir1,/data/local/tmp/tempDir2). " +
"Path names are restricted to the characters a-zA-Z0-9_-./+."]
)
var filesToDownload: List<String>? = null

@Option(
names = ["--results-dir"],
description = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,16 @@ class IosRunCommand : Runnable {
)
var testTargets: List<String>? = null

@Option(
names = ["--files-to-download"],
split = ",",
description = ["A list of paths that will be downloaded from the resulting bucket " +
"to the local results folder after the test is complete. These must be absolute paths " +
"(for example, --files-to-download /images/tempDir1,/data/local/tmp/tempDir2). " +
"Path names are restricted to the characters a-zA-Z0-9_-./+."]
)
var filesToDownload: List<String>? = null

@Option(
names = ["--test"],
description = ["The path to the test package (a zip file containing the iOS app " +
Expand Down
4 changes: 2 additions & 2 deletions test_runner/src/main/kotlin/ftl/reports/util/ReportManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import ftl.reports.MatrixResultsReport
import ftl.reports.xml.model.JUnitTestResult
import ftl.reports.xml.parseOneSuiteXml
import ftl.reports.xml.parseAllSuitesXml
import ftl.util.ArtifactRegex
import ftl.util.Artifacts
import ftl.util.resolveLocalRunPath
import java.io.File
import java.nio.file.Paths
Expand All @@ -23,7 +23,7 @@ object ReportManager {
val rootFolder = File(resolveLocalRunPath(matrices))

rootFolder.walk().forEach {
if (it.name.matches(ArtifactRegex.testResultRgx)) {
if (it.name.matches(Artifacts.testResultRgx)) {
xmlFiles.add(it)
}
}
Expand Down
16 changes: 6 additions & 10 deletions test_runner/src/main/kotlin/ftl/run/TestRunner.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import ftl.gc.GcToolResults
import ftl.json.MatrixMap
import ftl.json.SavedMatrix
import ftl.reports.util.ReportManager
import ftl.util.ArtifactRegex
import ftl.util.Artifacts
import ftl.util.MatrixState
import ftl.util.StopWatch
import ftl.util.Utils
Expand Down Expand Up @@ -188,8 +188,7 @@ object TestRunner {
return MatrixMap(map, path)
}

/** fetch test_result_0.xml & *.png **/
private fun fetchArtifacts(matrixMap: MatrixMap) {
private fun fetchArtifacts(matrixMap: MatrixMap, args: IArgs) {
println("FetchArtifacts")
val fields = Storage.BlobListOption.fields(Storage.BlobField.NAME)

Expand All @@ -200,20 +199,17 @@ object TestRunner {
finished && notDownloaded
}

val lastAndroidArgs = lastArgs() as? AndroidArgs
val directoriesToDownload = lastAndroidArgs?.directoriesToDownload ?: emptyList()

print(indent)
runBlocking {
filtered.forEach { matrix ->
launch {
val prefix = Storage.BlobListOption.prefix(matrix.gcsPathWithoutRootBucket)
val result = GcStorage.storage.list(matrix.gcsRootBucket, prefix, fields)
val artifactsToDownload = ArtifactRegex.artifactsToDownload(matrix, directoriesToDownload)
val artifactsList = Artifacts.regexList(args)

result.iterateAll().forEach { blob ->
val blobPath = blob.blobId.name
if (artifactsToDownload.find { blobPath.matches(it) } != null) {
if (artifactsList.any { blobPath.matches(it) }) {
val downloadFile = Paths.get(FtlConstants.localResultsDir, blobPath)
print(".")
if (!downloadFile.toFile().exists()) {
Expand Down Expand Up @@ -329,7 +325,7 @@ object TestRunner {

refreshMatrices(matrixMap, args)
pollMatrices(matrixMap, args)
fetchArtifacts(matrixMap)
fetchArtifacts(matrixMap, args)

// Must generate reports *after* fetching xml artifacts since reports require xml
val exitCode = ReportManager.generate(matrixMap, args)
Expand All @@ -350,7 +346,7 @@ object TestRunner {

if (!args.async) {
pollMatrices(matrixMap, args)
fetchArtifacts(matrixMap)
fetchArtifacts(matrixMap, args)

val exitCode = ReportManager.generate(matrixMap, args)
System.exit(exitCode)
Expand Down
22 changes: 0 additions & 22 deletions test_runner/src/main/kotlin/ftl/util/ArtifactRegex.kt

This file was deleted.

16 changes: 16 additions & 0 deletions test_runner/src/main/kotlin/ftl/util/Artifacts.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package ftl.util

import ftl.args.IArgs

object Artifacts {

val testResultRgx = Regex(".*test_result_\\d+\\.xml$")

/**
* @return a list of regex's that should be downloaded
*/
fun regexList(args: IArgs): List<Regex> {
val directoriesRegexToDownload = args.filesToDownload.map { Regex(it) }
return listOf(testResultRgx) + directoriesRegexToDownload
}
}
2 changes: 1 addition & 1 deletion test_runner/src/main/resources/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v4.1-SNAPSHOT
v4.2-SNAPSHOT
16 changes: 8 additions & 8 deletions test_runner/src/test/kotlin/ftl/args/AndroidArgsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class AndroidArgsTest {
flank:
testShards: 7
repeatTests: 8
directories-to-download:
files-to-download:
- /sdcard/screenshots
- /sdcard/screenshots2
test-targets-always-run:
Expand Down Expand Up @@ -157,7 +157,7 @@ class AndroidArgsTest {
// FlankYml
assert(testShards, 7)
assert(repeatTests, 8)
assert(directoriesToDownload, listOf("/sdcard/screenshots", "/sdcard/screenshots2"))
assert(filesToDownload, listOf("/sdcard/screenshots", "/sdcard/screenshots2"))
assert(
testTargetsAlwaysRun, listOf(
"class example.Test#grantPermission",
Expand Down Expand Up @@ -210,7 +210,7 @@ AndroidArgs
testShards: 7
repeatTests: 8
smartFlankGcsPath:${' '}
directories-to-download:
files-to-download:
- /sdcard/screenshots
- /sdcard/screenshots2
test-targets-always-run:
Expand Down Expand Up @@ -252,7 +252,7 @@ AndroidArgs
// FlankYml
assert(testShards, 1)
assert(repeatTests, 1)
assert(directoriesToDownload, empty)
assert(filesToDownload, empty)
assert(testTargetsAlwaysRun, empty)
}
}
Expand Down Expand Up @@ -485,19 +485,19 @@ AndroidArgs
}

@Test
fun cli_directoriesToDownload() {
fun cli_filesToDownload() {
val cli = AndroidRunCommand()
CommandLine(cli).parse("--directories-to-download=a,b")
CommandLine(cli).parse("--files-to-download=a,b")

val yaml = """
gcloud:
app: $appApk
test: $testApk
"""
assertThat(AndroidArgs.load(yaml).directoriesToDownload).isEmpty()
assertThat(AndroidArgs.load(yaml).filesToDownload).isEmpty()

val androidArgs = AndroidArgs.load(yaml, cli)
assertThat(androidArgs.directoriesToDownload).isEqualTo(listOf("a", "b"))
assertThat(androidArgs.filesToDownload).isEqualTo(listOf("a", "b"))
}

@Test
Expand Down
Loading

0 comments on commit f6e217f

Please sign in to comment.