Skip to content

Commit

Permalink
Params fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
eakurnikov committed Oct 11, 2021
1 parent 4b09959 commit b46e1a2
Show file tree
Hide file tree
Showing 14 changed files with 94 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class DumpLogcatTestInterceptor(
) : TestRunWatcherInterceptor {

override fun onTestStarted(testInfo: TestInfo) {
logcatDumper.watch()
logcatDumper.charge()
}

override fun onTestFinished(testInfo: TestInfo, success: Boolean) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import java.io.File

interface LogcatDumper {

fun watch()
/**
* Prepares for future logcat dump to file.
*/
fun charge()

/**
* Dumps logcat output with specific tag.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class LogcatDumperImpl(
private val dateTimeFormat = SimpleDateFormat("MM-dd HH:mm:ss.SSS", Locale.getDefault())
private var timeDumpFrom: String? = null

override fun watch() {
override fun charge() {
timeDumpFrom = dateTimeFormat.format(Date())
logger.i("Logcat buffer may be dumped from $timeDumpFrom")
}
Expand All @@ -31,13 +31,11 @@ class LogcatDumperImpl(
private fun doDump(tag: String, block: (File.() -> Unit)?) {
try {
val logcatFile: File = resourceFilesProvider.provideLogcatFile(tag)
logcat.apply {
dumpLogcat(
file = logcatFile,
tags = loggerTags,
timeFrom = timeDumpFrom
)
}
logcat.dumpLogcat(
file = logcatFile,
tags = loggerTags,
timeFrom = timeDumpFrom
)
block?.invoke(logcatFile)
} catch (e: Throwable) {
logger.e("Logcat dumping error occurred: ${Log.getStackTraceString(e)}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class NetworkImpl(
private val flakySafetyAlgorithm = FlakySafetyAlgorithm(logger)
private val currentOsVersion = Build.VERSION.SDK_INT
private val flakySafetyParams: FlakySafetyParams
get() = FlakySafetyParams.custom(
get() = FlakySafetyParams(
timeoutMs = 1000,
intervalMs = 100,
allowedExceptions = setOf(AdbServerException::class.java)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class ContinuouslyProviderImpl(

private fun getParams(timeoutMs: Long? = null, intervalMs: Long? = null): ContinuouslyParams {
val defaultParams = kaspresso.params.continuouslyParams
return ContinuouslyParams.custom(
return ContinuouslyParams(
timeoutMs = timeoutMs ?: defaultParams.timeoutMs,
intervalMs = intervalMs ?: defaultParams.intervalMs
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class FlakySafetyProviderGlobalImpl(
allowedExceptions: Set<Class<out Throwable>>? = null
): FlakySafetyParams {
val defaultParams = kaspresso.params.flakySafetyParams
return FlakySafetyParams.custom(
return FlakySafetyParams(
timeoutMs ?: defaultParams.timeoutMs,
intervalMs ?: defaultParams.intervalMs,
allowedExceptions ?: defaultParams.allowedExceptions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class FlakySafetyProviderSimpleImpl(
failureMessage: String?,
action: () -> T
): T = flakySafetyAlgorithm.invokeFlakySafely(
params = FlakySafetyParams.custom(
params = FlakySafetyParams(
timeoutMs ?: params.timeoutMs,
intervalMs ?: params.intervalMs,
allowedExceptions ?: params.allowedExceptions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ class DumpLogcatInterceptor(
) : TestRunWatcherInterceptor {

override fun onTestStarted(testInfo: TestInfo) {
logcatDumper.watch()
logcatDumper.charge("TestLogcat")
}

override fun onTestFinished(testInfo: TestInfo, success: Boolean) {
logcatDumper.dump("TestLogcat")
logcatDumper.dump()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import junit.framework.AssertionFailedError
* The class that holds all the necessary for [com.kaspersky.kaspresso.autoscroll.AutoScrollProviderImpl] and
* [com.kaspersky.kaspresso.autoscroll.WebAutoScrollProviderImpl] parameters.
*/
class AutoScrollParams private constructor(
class AutoScrollParams(
/**
* The set of exceptions, if caught, the [com.kaspersky.kaspresso.autoscroll.AutoScrollProviderImpl] or
* [com.kaspersky.kaspresso.autoscroll.WebAutoScrollProviderImpl] will autoscroll.
Expand All @@ -18,13 +18,15 @@ class AutoScrollParams private constructor(
) {

companion object {
val defaultAllowedExceptions: MutableSet<Class<out Throwable>> = mutableSetOf(
PerformException::class.java,
AssertionFailedError::class.java,
UiObjectNotFoundException::class.java,
UnfoundedUiObjectException::class.java
)

fun default() = AutoScrollParams(
allowedExceptions = setOf(
PerformException::class.java,
AssertionFailedError::class.java,
UiObjectNotFoundException::class.java,
UnfoundedUiObjectException::class.java
)
allowedExceptions = defaultAllowedExceptions
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,39 @@ package com.kaspersky.kaspresso.params
/**
* The class that holds all the necessary for [com.kaspersky.kaspresso.flakysafety.ContinuouslyProviderImpl] parameters.
*/
class ContinuouslyParams private constructor(
timeoutMs: Long,
intervalMs: Long
class ContinuouslyParams(
/**
* The timeout during which attempts will be made by the
* [com.kaspersky.kaspresso.flakysafety.ContinuouslyProviderImpl].
*/
val timeoutMs: Long,

/**
* The interval at which attempts will be made by the [com.kaspersky.kaspresso.flakysafety.ContinuouslyProviderImpl].
*/
val intervalMs: Long
) {
init {
require(timeoutMs > 0) { "Timeout must be > 0" }
require(intervalMs > 0) { "Interval must be > 0" }
require(timeoutMs > intervalMs ) { "Timeout must be > interval" }
}

companion object {
val defaultTimeoutMs: Long = 10_000L
val defaultIntervalMs: Long = 500L

fun default() = ContinuouslyParams(
timeoutMs = 10_000,
intervalMs = 500
timeoutMs = defaultTimeoutMs,
intervalMs = defaultIntervalMs
)

fun custom(timeoutMs: Long, intervalMs: Long) = ContinuouslyParams(
fun custom(
timeoutMs: Long = defaultTimeoutMs,
intervalMs: Long = defaultIntervalMs
) = ContinuouslyParams(
timeoutMs = timeoutMs,
intervalMs = intervalMs
)
}

/**
* The timeout during which attempts will be made by the
* [com.kaspersky.kaspresso.flakysafety.ContinuouslyProviderImpl].
*/
var timeoutMs: Long = timeoutMs
set(value) {
if (intervalMs >= value) throw IllegalArgumentException("An interval of attempts is shorter than timeout.")
field = value
}

/**
* The interval at which attempts will be made by the [com.kaspersky.kaspresso.flakysafety.ContinuouslyProviderImpl].
*/
var intervalMs: Long = intervalMs
set(value) {
if (value >= timeoutMs) throw IllegalArgumentException("An interval of attempts is shorter than timeout.")
field = value
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,56 +9,58 @@ import junit.framework.AssertionFailedError
/**
* The class that holds all the necessary for [com.kaspersky.kaspresso.flakysafety.FlakySafetyProviderSimpleImpl] parameters.
*/
class FlakySafetyParams private constructor(
timeoutMs: Long,
intervalMs: Long,
class FlakySafetyParams(
/**
* The timeout during which attempts will be made by the
* [com.kaspersky.kaspresso.flakysafety.FlakySafetyProviderSimpleImpl].
*/
val timeoutMs: Long,

/**
* The interval at which attempts will be made by the
* [com.kaspersky.kaspresso.flakysafety.FlakySafetyProviderSimpleImpl].
*/
val intervalMs: Long,

/**
* The set of exceptions, if caught, the [com.kaspersky.kaspresso.flakysafety.FlakySafetyProviderSimpleImpl] will continue
* to attempt.
*/
val allowedExceptions: Set<Class<out Throwable>>
) {
init {
require(timeoutMs > 0) { "Timeout must be > 0" }
require(intervalMs > 0) { "Interval must be > 0" }
require(timeoutMs > intervalMs ) { "Timeout must be > interval" }
}

companion object {
val defaultTimeoutMs: Long = 10_000L
val defaultIntervalMs: Long = 500L
val defaultAllowedExceptions: MutableSet<Class<out Throwable>> = mutableSetOf(
PerformException::class.java,
NoMatchingViewException::class.java,
AssertionError::class.java,
AssertionFailedError::class.java,
UnfoundedUiObjectException::class.java,
StaleObjectException::class.java,
IllegalStateException::class.java
)

fun default() = FlakySafetyParams(
timeoutMs = 10_000L,
intervalMs = 500L,
allowedExceptions = setOf(
PerformException::class.java,
NoMatchingViewException::class.java,
AssertionError::class.java,
AssertionFailedError::class.java,
UnfoundedUiObjectException::class.java,
StaleObjectException::class.java,
IllegalStateException::class.java
)
timeoutMs = defaultTimeoutMs,
intervalMs = defaultIntervalMs,
allowedExceptions = defaultAllowedExceptions
)

fun custom(
timeoutMs: Long,
intervalMs: Long,
allowedExceptions: Set<Class<out Throwable>>
): FlakySafetyParams = FlakySafetyParams(timeoutMs, intervalMs, allowedExceptions)
timeoutMs: Long = defaultTimeoutMs,
intervalMs: Long = defaultIntervalMs,
allowedExceptions: Set<Class<out Throwable>> = defaultAllowedExceptions
): FlakySafetyParams = FlakySafetyParams(
timeoutMs = timeoutMs,
intervalMs = intervalMs,
allowedExceptions = allowedExceptions
)
}

/**
* The timeout during which attempts will be made by the
* [com.kaspersky.kaspresso.flakysafety.FlakySafetyProviderSimpleImpl].
*/
var timeoutMs: Long = timeoutMs
set(value) {
if (intervalMs >= value) throw IllegalArgumentException("An interval of attempts is shorter than timeout.")
field = value
}

/**
* The interval at which attempts will be made by the
* [com.kaspersky.kaspresso.flakysafety.FlakySafetyProviderSimpleImpl].
*/
var intervalMs: Long = intervalMs
set(value) {
if (value >= timeoutMs) throw IllegalArgumentException("An interval of attempts is shorter than timeout.")
field = value
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ package com.kaspersky.kaspresso.params
/**
* @param quality quality of the PNG compression; range: 0-100
*/
data class ScreenshotParams(
class ScreenshotParams(
val quality: Int = 100
)
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ package com.kaspersky.kaspresso.params
/**
* The class that holds all the necessary for [com.kaspersky.kaspresso.testcases.core.step.StepsManager] parameters.
*/
data class StepParams(
class StepParams(
var autonumber: Boolean = true
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.kaspersky.kaspresso.params

data class VideoParams(
class VideoParams(
val startRecordingTimeMs: Long = 3_000L,
val stopRecordingTimeMs: Long = 2_000L,
val bitRate: Int = 1_000_000
Expand Down

0 comments on commit b46e1a2

Please sign in to comment.