Skip to content

Commit

Permalink
Merge pull request #66 from Malinskiy/bugfix/annotation_filter_for_gr…
Browse files Browse the repository at this point in the history
…oovy

Fix Filtering config and log video pull errors
  • Loading branch information
tagantroy authored Jul 17, 2018
2 parents a55388a + 2b3ded4 commit 7cfe04c
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,23 +1,33 @@
package com.malinskiy.marathon

import com.malinskiy.marathon.execution.AnnotationFilter
import com.malinskiy.marathon.execution.FilteringConfiguration
import com.malinskiy.marathon.execution.FullyQualifiedClassnameFilter
import com.malinskiy.marathon.execution.SimpleClassnameFilter
import com.malinskiy.marathon.execution.TestFilter
import com.malinskiy.marathon.execution.TestPackageFilter
import groovy.lang.Closure

open class FilteringPluginConfiguration {
var whitelist: MutableCollection<TestFilter> = mutableListOf()
var blacklist: MutableCollection<TestFilter> = mutableListOf()
//groovy
var groovyWhiteList: Wrapper? = null
var groovyBlackList: Wrapper? = null

fun whitelist(closure: Closure<*>) {
closure.delegate = whitelist
groovyWhiteList = Wrapper()
closure.delegate = groovyWhiteList
closure.call()
}

fun blacklist(closure: Closure<*>) {
closure.delegate = blacklist
groovyBlackList = Wrapper()
closure.delegate = groovyBlackList
closure.call()
}

//kts
var whitelist: MutableCollection<TestFilter> = mutableListOf()
var blacklist: MutableCollection<TestFilter> = mutableListOf()
fun whitelist(block: MutableCollection<TestFilter>.() -> Unit) {
whitelist.also(block)
}
Expand All @@ -27,6 +37,37 @@ open class FilteringPluginConfiguration {
}
}

open class Wrapper {
open var simpleClassNameFilter: ArrayList<String>? = null
open var fullyQualifiedClassnameFilter: ArrayList<String>? = null
open var testPackageFilter: ArrayList<String>? = null
open var annotationFilter: ArrayList<String>? = null
}

fun Wrapper.toList(): List<TestFilter> {
val mutableList = mutableListOf<TestFilter>()
this.annotationFilter?.map { AnnotationFilter(it.toRegex()) }?.let {
mutableList.addAll(it)
}
this.fullyQualifiedClassnameFilter?.map { FullyQualifiedClassnameFilter(it.toRegex()) }?.let {
mutableList.addAll(it)
}
this.testPackageFilter?.map { TestPackageFilter(it.toRegex()) }?.let {
mutableList.addAll(it)
}
this.simpleClassNameFilter?.map { SimpleClassnameFilter(it.toRegex()) }?.let {
mutableList.addAll(it)
}
return mutableList
}

fun FilteringPluginConfiguration.toFilteringConfiguration(): FilteringConfiguration {
if (groovyWhiteList != null || groovyBlackList != null) {
val white = groovyWhiteList?.toList() ?: emptyList()

val black = groovyBlackList?.toList() ?: emptyList()
return FilteringConfiguration(white, black)
}
return FilteringConfiguration(whitelist, blacklist)
}

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.malinskiy.marathon.android.executor.listeners.video

import com.android.ddmlib.IDevice
import com.android.ddmlib.SyncException
import com.android.ddmlib.testrunner.TestIdentifier
import com.malinskiy.marathon.android.AndroidDevice
import com.malinskiy.marathon.android.RemoteFileManager
Expand All @@ -23,13 +24,16 @@ internal class ScreenRecorderTestRunListener(private val fileManager: FileManage

private var hasFailed: Boolean = false
private var screenRecorderStopper: ScreenRecorderStopper? = null
private var thread: Thread? = null

private val awaitMillis = 10_000L

override fun testStarted(test: TestIdentifier) {
hasFailed = false

screenRecorderStopper = ScreenRecorderStopper(deviceInterface)
val screenRecorder = ScreenRecorder(deviceInterface, test)
Thread(screenRecorder, "ScreenRecorder").start()
thread = Thread(screenRecorder, "ScreenRecorder").also { it.start() }
}

override fun testFailed(test: TestIdentifier, trace: String) {
Expand All @@ -38,26 +42,31 @@ internal class ScreenRecorderTestRunListener(private val fileManager: FileManage

override fun testAssumptionFailure(test: TestIdentifier, trace: String) {
screenRecorderStopper!!.stopScreenRecord(hasFailed)
if (hasFailed) {
pullTestVideo(test)
pullVideo(test)
}

private fun pullVideo(test: TestIdentifier) {
try {
thread?.join(awaitMillis)
if (hasFailed) {
pullTestVideo(test)
}
removeTestVideo(test)
} catch (e: InterruptedException) {
logger.warn { "Can't stop recording" }
} catch (e: SyncException) {
logger.warn { "Can't pull video" }
}
removeTestVideo(test)
}

override fun testIgnored(test: TestIdentifier) {
screenRecorderStopper!!.stopScreenRecord(hasFailed)
if (hasFailed) {
pullTestVideo(test)
}
removeTestVideo(test)
pullVideo(test)
}

override fun testEnded(test: TestIdentifier, testMetrics: Map<String, String>) {
screenRecorderStopper!!.stopScreenRecord(hasFailed)
if (hasFailed) {
pullTestVideo(test)
}
removeTestVideo(test)
pullVideo(test)
}

private fun pullTestVideo(test: TestIdentifier) {
Expand Down

0 comments on commit 7cfe04c

Please sign in to comment.