From 7f79edd0880e7188b38fc0161b1bcc543c0dfc3a Mon Sep 17 00:00:00 2001 From: bootstraponline Date: Thu, 29 Nov 2018 14:31:41 -0500 Subject: [PATCH] Add progress bar when uploading --- release_notes.md | 4 ++- .../src/main/kotlin/ftl/gc/GcStorage.kt | 9 +++++++ .../src/main/kotlin/ftl/shard/Shard.kt | 1 + .../src/main/kotlin/ftl/util/ProgressBar.kt | 26 +++++++++++++++++++ .../test/kotlin/ftl/util/ProgressBarTest.kt | 25 ++++++++++++++++++ 5 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 test_runner/src/main/kotlin/ftl/util/ProgressBar.kt create mode 100644 test_runner/src/test/kotlin/ftl/util/ProgressBarTest.kt diff --git a/release_notes.md b/release_notes.md index a5dbb58f17..a1bbbffe22 100644 --- a/release_notes.md +++ b/release_notes.md @@ -1,7 +1,9 @@ ## v4.1 (unreleased) - `app`, `test`, and `xctestrun-file` now support `~`, environment variables, and globs (`*`, `**`) when resolving paths. [#386](https://github.com/TestArmada/flank/pull/386) - Update `flank android run` to support `--app`, `--test`, `--test-targets`, `--use-orchestrator` and `--no-use-orchestrator`. -- Add `smartFlankGcsPath` to shard iOS and Android tests by time using historical run data. The amount of shards used is set by `testShards`. +- Add `smartFlankGcsPath` to shard iOS and Android tests by time using historical run data. The amount of shards used is set by `testShards`. [#385](https://github.com/TestArmada/flank/pull/385) +- Fix parsing empty testcase [#402](https://github.com/TestArmada/flank/pull/402) +- Add progress bar when uploading files. ## v4.0.0 diff --git a/test_runner/src/main/kotlin/ftl/gc/GcStorage.kt b/test_runner/src/main/kotlin/ftl/gc/GcStorage.kt index ed35d1b446..745f55bcdb 100644 --- a/test_runner/src/main/kotlin/ftl/gc/GcStorage.kt +++ b/test_runner/src/main/kotlin/ftl/gc/GcStorage.kt @@ -12,6 +12,7 @@ import ftl.config.FtlConstants.GCS_PREFIX import ftl.reports.xml.model.JUnitTestResult import ftl.reports.xml.parseAllSuitesXml import ftl.reports.xml.xmlToString +import ftl.util.ProgressBar import ftl.util.Utils.fatalError import ftl.util.Utils.join import java.io.File @@ -54,10 +55,14 @@ object GcStorage { val fileBlob = BlobInfo.newBuilder(bucket, name).build() + val progress = ProgressBar() try { + progress.start("Uploading smart flank XML") storage.create(fileBlob, testResult.xmlToString().toByteArray()) } catch (e: Exception) { fatalError(e) + } finally { + progress.stop() } } @@ -98,10 +103,14 @@ object GcStorage { // 404 Not Found error when rootGcsBucket does not exist val fileBlob = BlobInfo.newBuilder(rootGcsBucket, join(runGcsPath, fileName)).build() + val progress = ProgressBar() try { + progress.start("Uploading $fileName") storage.create(fileBlob, fileBytes) } catch (e: Exception) { fatalError(e) + } finally { + progress.stop() } return gcsFilePath diff --git a/test_runner/src/main/kotlin/ftl/shard/Shard.kt b/test_runner/src/main/kotlin/ftl/shard/Shard.kt index 2ace9c991a..ffa1c2482d 100644 --- a/test_runner/src/main/kotlin/ftl/shard/Shard.kt +++ b/test_runner/src/main/kotlin/ftl/shard/Shard.kt @@ -111,6 +111,7 @@ object Shard { val allTests = testsToRun.size val cacheHit = allTests - cacheMiss val cachePercent = cacheHit.toDouble() / allTests * 100.0 + println() println(" Smart Flank cache hit: ${cachePercent.roundToInt()}% ($cacheHit / $allTests)") println(" Shard times: " + shards.joinToString(", ") { "${it.time.roundToInt()}s" } + "\n") diff --git a/test_runner/src/main/kotlin/ftl/util/ProgressBar.kt b/test_runner/src/main/kotlin/ftl/util/ProgressBar.kt new file mode 100644 index 0000000000..26ea0e1df7 --- /dev/null +++ b/test_runner/src/main/kotlin/ftl/util/ProgressBar.kt @@ -0,0 +1,26 @@ +package ftl.util + +import java.util.Timer +import java.util.TimerTask + +class ProgressBar { + private val task = ProgressBarTask() + private val timer = Timer(true) + + fun start(msg: String) { + print(" $msg ") + timer.scheduleAtFixedRate(task, 0, 10_000) + } + + fun stop() { + println() + timer.cancel() + task.cancel() + } +} + +private class ProgressBarTask : TimerTask() { + override fun run() { + print(".") + } +} diff --git a/test_runner/src/test/kotlin/ftl/util/ProgressBarTest.kt b/test_runner/src/test/kotlin/ftl/util/ProgressBarTest.kt new file mode 100644 index 0000000000..1eeb1bf5e4 --- /dev/null +++ b/test_runner/src/test/kotlin/ftl/util/ProgressBarTest.kt @@ -0,0 +1,25 @@ +package ftl.util + +import com.google.common.truth.Truth.assertThat +import org.junit.Rule +import org.junit.Test +import org.junit.contrib.java.lang.system.SystemOutRule + +class ProgressBarTest { + + @Rule + @JvmField + val systemOutRule: SystemOutRule = SystemOutRule().enableLog().muteForSuccessfulTests() + + @Test + fun progress_start_stop() { + val progress = ProgressBar() + + progress.start("hi") + Thread.sleep(300) + assertThat(systemOutRule.log).isEqualTo(" hi .") + + progress.stop() + assertThat(systemOutRule.log).isEqualTo(" hi .\n") + } +}