Bug 1469054 - Make sure the adb server stops. r?jdescottes
Without this change, the test in this patch does fail since when the test
starts, the adb server is still running for the previous test, thus
ADB.start() doesn't start a new adb server, then after that when we check
that the adb server is running by adb-running-checker, it tells us the adb
server is NOT running at that moment.
MozReview-Commit-ID: KRo30WmAsAY
--- a/devtools/shared/adb/adb.js
+++ b/devtools/shared/adb/adb.js
@@ -9,16 +9,18 @@
const { Cc, Ci } = require("chrome");
const EventEmitter = require("devtools/shared/event-emitter");
const client = require("./adb-client");
const { getFileForBinary } = require("./adb-binary");
const { setTimeout } = require("resource://gre/modules/Timer.jsm");
const { PromiseUtils } = require("resource://gre/modules/PromiseUtils.jsm");
const { OS } = require("resource://gre/modules/osfile.jsm");
const { Services } = require("resource://gre/modules/Services.jsm");
+loader.lazyRequireGetter(this, "check",
+ "devtools/shared/adb/adb-running-checker", true);
let ready = false;
let didRunInitially = false;
const OKAY = 0x59414b4f;
// const FAIL = 0x4c494146;
// const STAT = 0x54415453;
const DATA = 0x41544144;
@@ -52,17 +54,17 @@ const ADB = {
start() {
return new Promise(async (resolve, reject) => {
let onSuccessfulStart = () => {
Services.obs.notifyObservers(null, "adb-ready");
this.ready = true;
resolve();
};
- let isAdbRunning = await require("./adb-running-checker").check();
+ let isAdbRunning = await check();
if (isAdbRunning) {
this.didRunInitially = false;
console.log("Found ADB process running, not restarting");
onSuccessfulStart();
return;
}
console.log("Didn't find ADB process running, restarting");
@@ -106,16 +108,27 @@ const ADB = {
* In case, we do need to kill the server, this param is passed through
* to kill to determine whether it's a sync operation.
*/
async stop(sync) {
if (!this.didRunInitially) {
return; // We didn't start the server, nothing to do
}
await this.kill(sync);
+ // Make sure the ADB server stops listening.
+ //
+ // kill() above doesn't mean that the ADB server stops, it just means that
+ // 'adb kill-server' command finished, so that it's possible that the ADB
+ // server is still alive there.
+ while (true) {
+ const isAdbRunning = await check();
+ if (!isAdbRunning) {
+ break;
+ }
+ }
},
/**
* Kill the ADB server. We do this by running ADB again, passing it
* the "kill-server" argument.
*
* @param {Boolean} sync
* Whether or not to kill the server synchronously. In general,
--- a/devtools/shared/adb/test/test_adb.js
+++ b/devtools/shared/adb/test/test_adb.js
@@ -175,8 +175,49 @@ add_task(async function testStartAndStop
ok(await check(), "adb is now running");
await ADB.stop(true /* sync */);
ok(!ADB.ready);
await extension.unload();
});
+add_task(async function testTrackDevices() {
+ const extension = ExtensionTestUtils.loadExtension({
+ manifest: {
+ version: "1.0",
+ applications: {
+ gecko: { id: "adb@mozilla.org" }
+ }
+ },
+ files: {
+ "adb.json": JSON.stringify(ADB_JSON),
+ "linux/adb": adbMock,
+ "linux64/adb": adbMock,
+ "mac64/adb": adbMock,
+ "win32/adb.exe": adbMock,
+ "win32/AdbWinApi.dll": "dummy",
+ "win32/AdbWinUsbApi.dll": "dummy"
+ },
+ });
+
+ await extension.startup();
+
+ await ADB.start();
+ ok(ADB.ready);
+
+ ok(await check(), "adb is now running");
+
+ const receivedDeviceId = await new Promise(resolve => {
+ EventEmitter.on(ADB, "device-connected", deviceId => {
+ resolve(deviceId);
+ });
+ ADB.trackDevices();
+ });
+
+ equal(receivedDeviceId, "1234567890");
+
+ await ADB.stop(true /* sync */);
+ ok(!ADB.ready);
+
+ await extension.unload();
+});
+