Bug 1169290 - Tell running state from whether server is alive. r?maja_zf
This has the advantage that we no longer have to maintain a boolean
state manually to tell whether the Marionette server is running.
In other words, the Marionette service is running whenever the TCP
listener has been started and is alive.
MozReview-Commit-ID: 59mxXBGUIOn
--- a/testing/marionette/components/marionette.js
+++ b/testing/marionette/components/marionette.js
@@ -132,17 +132,16 @@ const prefs = {
}
}
}
},
};
class MarionetteComponent {
constructor() {
- this.running = false;
this.server = null;
// holds reference to ChromeWindow
// used to run GFX sanity tests on Windows
this.gfxWindow = null;
// indicates that all pending window checks have been completed
// and that we are ready to start the Marionette server
@@ -151,16 +150,20 @@ class MarionetteComponent {
log.level = prefs.logLevel;
this.enabled = env.exists(ENV_ENABLED);
if (this.enabled) {
log.info(`Enabled via ${ENV_ENABLED}`);
}
}
+ get running() {
+ return this.server && this.server.alive;
+ }
+
// Handle -marionette flag
handle(cmdLine) {
if (!this.enabled && cmdLine.handleFlag("marionette", false)) {
this.enabled = true;
log.debug("Enabled via flag");
}
}
@@ -266,30 +269,27 @@ class MarionetteComponent {
await startupRecorder;
try {
ChromeUtils.import("chrome://marionette/content/server.js");
let listener = new server.TCPListener(prefs.port);
listener.start();
log.info(`Listening on port ${listener.port}`);
this.server = listener;
- this.running = true;
} catch (e) {
log.fatal("Remote protocol server failed to start", e);
Services.startup.quit(Ci.nsIAppStartup.eForceQuit);
}
});
}
uninit() {
- if (!this.running) {
- return;
+ if (this.running) {
+ this.server.stop();
}
- this.server.stop();
- this.running = false;
}
get QueryInterface() {
return XPCOMUtils.generateQI([
Ci.nsICommandLineHandler,
Ci.nsIMarionette,
]);
}