Skip to content

Commit

Permalink
chore(logging): Made some logging clearer and make sure not to overwr…
Browse files Browse the repository at this point in the history
…ite exit codes (#163)
  • Loading branch information
sjelin authored and heathkit committed Nov 28, 2016
1 parent a7c6eb5 commit 7a08b8a
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions lib/cmds/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ if (argv._[0] === 'start-run') {

// Manage processes used in android emulation
let androidProcesses: ChildProcess[] = [];
let androidActiveAVDs: string[] = [];

/**
* Parses the options and starts the selenium standalone server.
Expand Down Expand Up @@ -212,7 +213,10 @@ function start(options: Options) {
seleniumProcess.on('exit', (code: number) => {
logger.info('Selenium Standalone has exited with code ' + code);
shutdownEverything();
process.exit(code);
process.exit(process.exitCode || code);
});
seleniumProcess.on('error', (error: Error) => {
logger.warn('Selenium Standalone server encountered an error: ' + error);
});
process.stdin.resume();
process.stdin.on('data', (chunk: Buffer) => {
Expand Down Expand Up @@ -242,32 +246,41 @@ function startAndroid(
avds.length + ' android devices');
}
avds.forEach((avd: string, i: number) => {
logger.info('Booting up AVD ' + avd);
// Credit to appium-ci, which this code was adapted from
let emuBin = 'emulator'; // TODO(sjelin): get the 64bit linux version working
let emuArgs = [
'-avd',
avd + '-v' + sdk.versionCustom + '-wd-manager',
'-netfast',
];
let portArg = null;
if (!useSnapshots) {
emuArgs = emuArgs.concat(['-no-snapshot-load', '-no-snapshot-save']);
}
if (port) {
emuArgs = emuArgs.concat(['-port', '' + (port + 2 * i)]);
portArg = port + i * 2;
emuArgs = emuArgs.concat(['-port', '' + portArg]);
}
if (emuBin !== 'emulator') {
emuArgs = emuArgs.concat(['-qemu', '-enable-kvm']);
}
androidProcesses.push(spawn(path.resolve(sdkPath, 'tools', emuBin), emuArgs, stdio));
logger.info(
'Starting ' + avd + ' on ' + (portArg == null ? 'default port' : 'port ' + portArg));
let child = spawn(path.resolve(sdkPath, 'tools', emuBin), emuArgs, stdio);
child.on('error', (error: Error) => {
logger.warn(avd + ' encountered an error: ' + error);
});
androidProcesses.push(child);
androidActiveAVDs.push(avd);
});
}

function killAndroid() {
androidProcesses.forEach((androidProcess: ChildProcess) => {
androidProcess.kill();
});
androidProcesses.length = 0;
for (var i = 0; i < androidProcesses.length; i++) {
logger.info('Shutting down ' + androidActiveAVDs[i]);
androidProcesses[i].kill();
}
androidProcesses.length = androidActiveAVDs.length = 0;
}

// Manage appium process
Expand Down

0 comments on commit 7a08b8a

Please sign in to comment.