Skip to content

Commit

Permalink
fix(android): fail early on missing input files
Browse files Browse the repository at this point in the history
  • Loading branch information
Malinskiy committed Nov 13, 2023
1 parent a6c1281 commit 3ce16d4
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ class LogicalConfigurationValidator : ConfigurationValidator {
is VendorConfiguration.IOSConfiguration -> {
configuration.vendorConfiguration.validate()
}
is VendorConfiguration.AndroidConfiguration -> {
configuration.vendorConfiguration.validate()

Check warning on line 31 in configuration/src/main/kotlin/com/malinskiy/marathon/config/LogicalConfigurationValidator.kt

View check run for this annotation

Codecov / codecov/patch

configuration/src/main/kotlin/com/malinskiy/marathon/config/LogicalConfigurationValidator.kt#L31

Added line #L31 was not covered by tests
}

else -> Unit
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,26 @@ sealed class VendorConfiguration {
@JsonProperty("disableWindowAnimation") val disableWindowAnimation: Boolean = DEFAULT_DISABLE_WINDOW_ANIMATION,
) : VendorConfiguration() {
fun safeAndroidSdk(): File = androidSdk ?: throw ConfigurationException("No android SDK path specified")

fun validate() {
validateFile(applicationOutput)
validateFile(testApplicationOutput)

Check warning on line 78 in configuration/src/main/kotlin/com/malinskiy/marathon/config/vendor/VendorConfiguration.kt

View check run for this annotation

Codecov / codecov/patch

configuration/src/main/kotlin/com/malinskiy/marathon/config/vendor/VendorConfiguration.kt#L77-L78

Added lines #L77 - L78 were not covered by tests
splitApks?.forEach { validateFile(it) }
extraApplicationsOutput?.forEach { validateFile(it) }
outputs?.forEach {
validateFile(it.application)
validateFile(it.testApplication)

Check warning on line 83 in configuration/src/main/kotlin/com/malinskiy/marathon/config/vendor/VendorConfiguration.kt

View check run for this annotation

Codecov / codecov/patch

configuration/src/main/kotlin/com/malinskiy/marathon/config/vendor/VendorConfiguration.kt#L82-L83

Added lines #L82 - L83 were not covered by tests
it.splitApks?.forEach { apk -> validateFile(apk) }
it.extraApplications?.forEach { apk -> validateFile(apk) }
}
}

private fun validateFile(file: File?) {
if (file != null) {
if (!file.exists()) throw ConfigurationException("${file.absolutePath} does not exist")
if (!file.isFile) throw ConfigurationException("${file.absolutePath} must be a regular file")
}
}
}

class AndroidConfigurationBuilder {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class AdamDeviceProvider(
private val socketFactory = VertxSocketFactory(idleTimeout = vendorConfiguration.timeoutConfiguration.socketIdleTimeout.toMillis())
private val logcatManager: LogcatManager = LogcatManager()
private lateinit var deviceEventsChannel: ReceiveChannel<Pair<AndroidDebugBridgeClient, List<Device>>>
private var deviceEventsChannelInitialized = false
private val deviceEventsChannelMutex = Mutex()
private val multiServerDeviceStateTracker = MultiServerDeviceStateTracker()

Expand Down Expand Up @@ -132,6 +133,7 @@ class AdamDeviceProvider(
}
}
}
deviceEventsChannelInitialized = true
}
for ((client, currentDeviceList) in deviceEventsChannel) {
multiServerDeviceStateTracker.update(client, currentDeviceList).forEach { update ->
Expand Down Expand Up @@ -160,6 +162,7 @@ class AdamDeviceProvider(
devices[serial] = ProvidedDevice(device, job)
}
}

TrackingUpdate.DISCONNECTED -> {
devices[serial]?.let { (device, job) ->
if (job.isActive) {
Expand All @@ -169,6 +172,7 @@ class AdamDeviceProvider(
device.dispose()
}
}

TrackingUpdate.NOTHING_TO_DO -> Unit
}
logger.debug { "Device $serial changed state to $state" }
Expand All @@ -180,7 +184,7 @@ class AdamDeviceProvider(

override suspend fun borrow(): AdamAndroidDevice {
var availableDevices = devices.filter { it.value.setupJob.isCompleted && !it.value.setupJob.isCancelled }
while(availableDevices.isEmpty()) {
while (availableDevices.isEmpty()) {
delay(200)
availableDevices = devices.filter { it.value.setupJob.isCompleted && !it.value.setupJob.isCancelled }
}
Expand All @@ -198,7 +202,9 @@ class AdamDeviceProvider(
providerJob?.cancel()
channel.close()
deviceEventsChannelMutex.withLock {
deviceEventsChannel.cancel()
if (deviceEventsChannelInitialized) {
deviceEventsChannel.cancel()
}
}
logcatManager.close()
socketFactory.close()
Expand Down

0 comments on commit 3ce16d4

Please sign in to comment.