Skip to content

Commit

Permalink
chore: Simplify booting status monitoring (#250)
Browse files Browse the repository at this point in the history
  • Loading branch information
mykola-mokhnach authored Jul 3, 2024
1 parent c7a1180 commit 508a2e5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
35 changes: 20 additions & 15 deletions lib/subcommands/bootstatus.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import log from '../logger';
import { waitForCondition } from 'asyncbox';

import _ from 'lodash';

const commands = {};

Expand Down Expand Up @@ -40,7 +40,8 @@ commands.startBootMonitor = async function startBootMonitor (opts = {}) {
} = opts;
const udid = this.requireUdid('bootstatus');

let status = '';
/** @type {string[]} */
const status = [];
let isBootingFinished = false;
let error = null;
let timeoutHandler = null;
Expand All @@ -52,17 +53,18 @@ commands.startBootMonitor = async function startBootMonitor (opts = {}) {
args,
asynchronous: true,
});
bootMonitor.on('output', (stdout, stderr) => {
status += stdout || stderr;
if (stdout) {
if (stdout.includes('Waiting on Data Migration') && onWaitingDataMigration) {
onWaitingDataMigration();
} else if (stdout.includes('Waiting on System App') && onWaitingSystemApp) {
onWaitingSystemApp();
}
const onStreamLine = (/** @type {string} */ line) => {
status.push(line);
if (onWaitingDataMigration && line.includes('Waiting on Data Migration')) {
onWaitingDataMigration();
} else if (onWaitingSystemApp && line.includes('Waiting on System App')) {
onWaitingSystemApp();
}
});
bootMonitor.on('exit', (code, signal) => {
};
for (const streamName of ['stdout', 'stderr']) {
bootMonitor.on(`line-${streamName}`, onStreamLine);
}
bootMonitor.once('exit', (code, signal) => {
if (timeoutHandler) {
clearTimeout(timeoutHandler);
}
Expand All @@ -72,8 +74,10 @@ commands.startBootMonitor = async function startBootMonitor (opts = {}) {
}
isBootingFinished = true;
} else {
status = status || signal;
error = new Error(status);
const errMessage = _.isEmpty(status)
? `The simulator booting process has exited with code ${code} by signal ${signal}`
: status.join('\n');
error = new Error(errMessage);
if (onError) {
onError(error);
}
Expand Down Expand Up @@ -105,7 +109,8 @@ commands.startBootMonitor = async function startBootMonitor (opts = {}) {
const [seconds] = process.hrtime(start);
throw new Error(
`The simulator ${udid} has failed to finish booting after ${seconds}s. ` +
`Original status: ${status}`);
`Original status: ${status.join('\n')}`
);
}
}
return bootMonitor;
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"rimraf": "^5.0.0",
"semver": "^7.0.0",
"source-map-support": "^0.x",
"teen_process": "^2.0.0",
"teen_process": "^2.2.0",
"uuid": "^10.0.0",
"which": "^4.0.0"
},
Expand All @@ -61,7 +61,6 @@
"singleQuote": true
},
"devDependencies": {
"@appium/eslint-config-appium": "^8.0.4",
"@appium/eslint-config-appium-ts": "^0.x",
"@appium/tsconfig": "^0.x",
"@appium/types": "^0.x",
Expand Down

0 comments on commit 508a2e5

Please sign in to comment.