Repository: runningcode/fladle
Pull request #137 (2020-06-05 10:36:39)

Add time units support for timeout
Feature request #136 

pawelpasterz: Hey @runningcode , please tak a look, thanks!
bootstraponline: hey, what's the status of this pull request?
pawelpasterz: @bootstraponline 
Since `Property` problem for additional configs is not solved yet (https://github.com/runningcode/fladle/pull/126#issuecomment-645754679) I am not sure if I should attach this to PR scope. See my comment above. But it's up to @runningcode :)
runningcode: Sorry for taking so long, yeah let's merge this for now and figure out how to fix the additional configs problem later.

Patch:
diff --git a/buildSrc/src/main/java/com/osacky/flank/gradle/FladleConfig.kt b/buildSrc/src/main/java/com/osacky/flank/gradle/FladleConfig.kt
index d0539e8..479f1a7 100644
--- a/buildSrc/src/main/java/com/osacky/flank/gradle/FladleConfig.kt
+++ b/buildSrc/src/main/java/com/osacky/flank/gradle/FladleConfig.kt
@@ -31,8 +31,6 @@ interface FladleConfig {
 
   var resultsHistoryName: String?
 
-  var timeoutMin: Int
-
   var directoriesToPull: List<String>
 
   var filesToDownload: List<String>
@@ -149,4 +147,18 @@ interface FladleConfig {
    * Values are only permitted for text type elements, so no value should be specified for click and ignore type elements.
    */
   var roboDirectives: List<List<String>>
+
+  /**
+   * The max time test execution can run before it is cancelled (default: 15m).
+   * It does not include any time necessary to prepare and clean up the target device.
+   * The maximum possible testing time is 45m on physical devices and 60m on virtual devices.
+   * The TIMEOUT units can be h, m, or s. If no unit is given, seconds are assumed.
+   *
+   * Examples:
+   * * 1h   -> 1 hour
+   * * 5m   -> 5 minutes
+   * * 200s -> 200 seconds
+   * * 100  -> 100 seconds
+   */
+  var testTimeout: String
 }
diff --git a/buildSrc/src/main/java/com/osacky/flank/gradle/FladleConfigImpl.kt b/buildSrc/src/main/java/com/osacky/flank/gradle/FladleConfigImpl.kt
index 5f2a796..d210a6d 100644
--- a/buildSrc/src/main/java/com/osacky/flank/gradle/FladleConfigImpl.kt
+++ b/buildSrc/src/main/java/com/osacky/flank/gradle/FladleConfigImpl.kt
@@ -21,7 +21,6 @@ data class FladleConfigImpl(
   override var directoriesToPull: List<String>,
   override var filesToDownload: List<String>,
   override var environmentVariables: Map<String, String>,
-  override var timeoutMin: Int,
   override var recordVideo: Boolean,
   override var performanceMetrics: Boolean,
   override var resultsBucket: String?,
@@ -40,5 +39,6 @@ data class FladleConfigImpl(
   override var otherFiles: Map<String, String>,
   override var networkProfile: String?,
   override var roboScript: String?,
-  override var roboDirectives: List<List<String>>
+  override var roboDirectives: List<List<String>>,
+  override var testTimeout: String
 ) : FladleConfig
diff --git a/buildSrc/src/main/java/com/osacky/flank/gradle/FlankGradleExtension.kt b/buildSrc/src/main/java/com/osacky/flank/gradle/FlankGradleExtension.kt
index 810e28e..cd37641 100644
--- a/buildSrc/src/main/java/com/osacky/flank/gradle/FlankGradleExtension.kt
+++ b/buildSrc/src/main/java/com/osacky/flank/gradle/FlankGradleExtension.kt
@@ -49,8 +49,6 @@ open class FlankGradleExtension @Inject constructor(objects: ObjectFactory) : Fl
 
   override var environmentVariables: Map<String, String> = emptyMap()
 
-  override var timeoutMin: Int = 15
-
   override var recordVideo: Boolean = true
 
   override var performanceMetrics: Boolean = true
@@ -89,6 +87,8 @@ open class FlankGradleExtension @Inject constructor(objects: ObjectFactory) : Fl
 
   override var roboDirectives: List<List<String>> = emptyList()
 
+  override var testTimeout: String = "15m"
+
   val configs: NamedDomainObjectContainer<FladleConfigImpl> = objects.domainObjectContainer(FladleConfigImpl::class.java) {
     FladleConfigImpl(
       name = it,
@@ -107,7 +107,6 @@ open class FlankGradleExtension @Inject constructor(objects: ObjectFactory) : Fl
       directoriesToPull = directoriesToPull,
       filesToDownload = filesToDownload,
       environmentVariables = environmentVariables,
-      timeoutMin = timeoutMin,
       recordVideo = recordVideo,
       performanceMetrics = performanceMetrics,
       resultsBucket = resultsBucket,
@@ -126,7 +125,8 @@ open class FlankGradleExtension @Inject constructor(objects: ObjectFactory) : Fl
       otherFiles = otherFiles,
       networkProfile = networkProfile,
       roboScript = roboScript,
-      roboDirectives = roboDirectives
+      roboDirectives = roboDirectives,
+      testTimeout = testTimeout
     )
   }
 
diff --git a/buildSrc/src/main/java/com/osacky/flank/gradle/YamlWriter.kt b/buildSrc/src/main/java/com/osacky/flank/gradle/YamlWriter.kt
index 0ff7edb..1e5f566 100644
--- a/buildSrc/src/main/java/com/osacky/flank/gradle/YamlWriter.kt
+++ b/buildSrc/src/main/java/com/osacky/flank/gradle/YamlWriter.kt
@@ -100,7 +100,7 @@ internal class YamlWriter {
     appendln("  auto-google-login: ${config.autoGoogleLogin}")
     appendln("  record-video: ${config.recordVideo}")
     appendln("  performance-metrics: ${config.performanceMetrics}")
-    appendln("  timeout: ${config.timeoutMin}m")
+    appendln("  timeout: ${config.testTimeout}")
 
     config.resultsHistoryName?.let {
       appendln("  results-history-name: $it")
diff --git a/docs/configuration.md b/docs/configuration.md
index 34de441..bb3f77e 100644
--- a/docs/configuration.md
+++ b/docs/configuration.md
@@ -54,7 +54,7 @@ fladle {
     testTargets = [
         "class com.osacky.flank.gradle.sample.ExampleInstrumentedTest#seeView"
     ]
-    timeoutMin = 15
+    testTimeout = "15m"
     recordVideo = false
     performanceMetrics = false
     devices = [
@@ -250,8 +250,13 @@ A list of paths that will be copied from the device's storage to the designated
 ### filesToDownload
 List of regex that is matched against bucket paths (for example: `2019-01-09_00:13:06.106000_YCKl/shard_0/NexusLowRes-28-en-portrait/bugreport.txt`) for files to be downloaded after a flank run.
 
-### timeoutMin
-The max time in minutes this test execution can run before it is cancelled (default: 15 min). It does not include any time necessary to prepare and clean up the target device. The maximum possible testing time is 30m on physical devices and 60m on virtual devices.
+### testTimeout
+The max time test execution can run before it is cancelled (default: 15m). It does not include any time necessary to prepare and clean up the target device. The maximum possible testing time is 45m on physical devices and 60m on virtual devices. The TIMEOUT units can be h, m, or s. If no unit is given, seconds are assumed.
+Examples:
+* 1h   -> 1 hour
+* 5m   -> 5 minutes
+* 200s -> 200 seconds
+* 100  -> 100 seconds
 
 ### recordVideo
 Enable video recording during the test. Enabled by default.


Test patch:
diff --git a/buildSrc/src/test/java/com/osacky/flank/gradle/YamlWriterTest.kt b/buildSrc/src/test/java/com/osacky/flank/gradle/YamlWriterTest.kt
index 82807a2..c05c878 100644
--- a/buildSrc/src/test/java/com/osacky/flank/gradle/YamlWriterTest.kt
+++ b/buildSrc/src/test/java/com/osacky/flank/gradle/YamlWriterTest.kt
@@ -626,7 +626,7 @@ class YamlWriterTest {
       autoGoogleLogin = true
       recordVideo = false
       performanceMetrics = false
-      timeoutMin = 45
+      testTimeout = "45m"
     }
 
     assertEquals("  use-orchestrator: true\n" +