Bug 1169290 - Tell running state from whether server is alive. r?maja_zf draft
authorAndreas Tolfsen <ato@sny.no>
Sat, 27 Jan 2018 18:46:17 +0000
changeset 753892 b7bc98d4dcadb71e7b8c312fa2b20a638048d94c
parent 753891 f49e626aac8b73bdb2f1ba53eb4c90cbb6deb4a0
child 753893 57776fa5e3a44a70d8b35586320d31d3f34769d4
push id98715
push userbmo:ato@sny.no
push dateMon, 12 Feb 2018 16:37:16 +0000
reviewersmaja_zf
bugs1169290
milestone60.0a1
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
testing/marionette/components/marionette.js
--- 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,
     ]);
   }