From dba467ce2e51ed95a2c671f408d12d57151335c2 Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Thu, 1 Jun 2023 13:20:34 +0200 Subject: [PATCH] fix: Properly handle the situation where reboot_readiness check returns a non-zero exit code --- lib/tools/system-calls.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/tools/system-calls.js b/lib/tools/system-calls.js index 7e519601..9c92fd8e 100644 --- a/lib/tools/system-calls.js +++ b/lib/tools/system-calls.js @@ -34,6 +34,7 @@ const SDK_BINARY_ROOTS = [ ]; const MIN_DELAY_ADB_API_LEVEL = 28; const REQUIRED_SERVICES = ['activity', 'package', 'mount']; +const SUBSYSTEM_STATE_OK = 'Subsystem state: true'; /** * Retrieve full path to the given binary. @@ -526,7 +527,7 @@ systemCallMethods.adbExec = async function adbExec (cmd, opts = {}) { * @param {!Array.|string} cmd - The array of rest command line parameters or a single * string parameter. * @param {?ShellExecOptions} opts [{}] - Additional options mapping. - * @return {string} - Command's stdout. + * @return {Promise} - Command's stdout. * @throws {Error} If the command returned non-zero exit code. */ systemCallMethods.shell = async function shell (cmd, opts = {}) { @@ -958,11 +959,14 @@ systemCallMethods.waitForEmulatorReady = async function waitForEmulatorReady (ti await waitForCondition(async () => { try { reason = await this.shell(['cmd', 'reboot_readiness', 'check-subsystems-state', '--list-blocking']); - return _.includes(reason, 'Subsystem state: true'); } catch (err) { - log.debug(`Waiting for emulator startup. Intermediate error: ${err.message}`); - return false; + // https://github.com/appium/appium/issues/18717 + reason = err.stdout || err.stderr; + if (!_.includes(reason, SUBSYSTEM_STATE_OK)) { + log.debug(`Waiting for emulator startup. Intermediate error: ${err.message}`); + } } + return _.includes(reason, SUBSYSTEM_STATE_OK); }, { waitMs: timeoutMs, intervalMs: 1000,