Skip to content

Commit

Permalink
Remove duplicate waiting for a device logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Chelombitko committed Dec 20, 2024
1 parent c958f8a commit 286a051
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,10 @@ class Scheduler(
initializeCache(scope)

try {
logger.debug("Waiting for a device...")
withTimeout(deviceProvider.deviceInitializationTimeoutMillis) {
while (pools.isEmpty()) {
delay(100)
delay(500L)
}
}
} catch (e: TimeoutCancellationException) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import com.malinskiy.marathon.device.DeviceEvent
import com.malinskiy.marathon.device.DeviceEvent.DeviceConnected
import com.malinskiy.marathon.device.DeviceEvent.DeviceDisconnected
import com.malinskiy.marathon.device.DeviceProvider
import com.malinskiy.marathon.exceptions.NoDevicesException
import com.malinskiy.marathon.execution.Configuration
import com.malinskiy.marathon.execution.StrictRunChecker
import com.malinskiy.marathon.io.AttachmentManager
Expand Down Expand Up @@ -68,33 +67,7 @@ class DdmlibDeviceProvider(
AndroidDebugBridge.addDeviceChangeListener(this)

logger.debug("Creating ADB bridge")
val adb = AndroidDebugBridge.createBridge(vendorConfiguration.adbPath.absolutePath, false, ADB_INIT_TIMEOUT.toMillis(), TimeUnit.MILLISECONDS)

var getDevicesCountdown = config.noDevicesTimeoutMillis
val sleepTime = DEFAULT_DDM_LIB_SLEEP_TIME
while (!adb.hasInitialDeviceList() || !adb.hasDevices() && getDevicesCountdown >= 0) {
logger.debug("No devices, waiting...")

try {
delay(sleepTime)
} catch (e: InterruptedException) {
throw TimeoutException("Timeout getting device list", e)
}
getDevicesCountdown -= sleepTime
}

logger.debug("Finished waiting for a device")

if (adb.devices.isNotEmpty()) {
logger.debug("Initial connected devices: {}", adb.devices.joinToString(", "))
adb.devices.forEach {
deviceConnected(it)
}
}

if (!adb.hasInitialDeviceList() || !adb.hasDevices()) {
throw NoDevicesException()
}
AndroidDebugBridge.createBridge(vendorConfiguration.adbPath.absolutePath, false, ADB_INIT_TIMEOUT.toMillis(), TimeUnit.MILLISECONDS)
}

private fun getDeviceOrPut(androidDevice: DdmlibAndroidDevice): DdmlibAndroidDevice {
Expand All @@ -118,8 +91,6 @@ class DdmlibDeviceProvider(
}
}

private fun AndroidDebugBridge.hasDevices(): Boolean = devices.isNotEmpty()

override suspend fun terminate() {
job.completeRecursively()
job.join()
Expand Down Expand Up @@ -250,6 +221,5 @@ class DdmlibDeviceProvider(
companion object {
private val ADB_INIT_TIMEOUT = Duration.ofSeconds(60)
private const val DEFAULT_DDM_LIB_TIMEOUT = 30000
private const val DEFAULT_DDM_LIB_SLEEP_TIME = 500L
}
}

0 comments on commit 286a051

Please sign in to comment.