Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Simplify booting status monitoring #250

Merged
merged 2 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading