Bug 1336776 - Log more useful error messages if MOZ_NODE_PATH environment variable is not set correctly. r?nwgh draft
authorChris Peterson <cpeterson@mozilla.com>
Sat, 04 Feb 2017 16:21:58 -0800
changeset 479519 6467275ec7cef4271bd94c6499113f51ebd661c0
parent 479455 12c02bf624c48903b155428f7c8a419ba7a333a6
child 544706 9588420f2ee0fd71a62457481fa34213f7febcae
push id44277
push usercpeterson@mozilla.com
push dateMon, 06 Feb 2017 21:07:52 +0000
reviewersnwgh
bugs1336776
milestone54.0a1
Bug 1336776 - Log more useful error messages if MOZ_NODE_PATH environment variable is not set correctly. r?nwgh MozReview-Commit-ID: Fevu9smKdu3
testing/xpcshell/runxpcshelltests.py
--- a/testing/xpcshell/runxpcshelltests.py
+++ b/testing/xpcshell/runxpcshelltests.py
@@ -981,53 +981,60 @@ class XPCShellTests(object):
           On a remote system, we need to overload this to work on the remote filesystem.
         """
         return os.path.abspath(dirname)
 
     def trySetupNode(self):
         """
           Run node for HTTP/2 tests, if available, and updates mozinfo as appropriate.
         """
-        nodeBin = None
+        if os.getenv('MOZ_ASSUME_NODE_RUNNING', None):
+            self.log.info('Assuming required node servers are already running')
+            return
 
         # We try to find the node executable in the path given to us by the user in
         # the MOZ_NODE_PATH environment variable
-        localPath = os.getenv('MOZ_NODE_PATH', None)
-        if localPath and os.path.exists(localPath) and os.path.isfile(localPath):
-            nodeBin = localPath
+        nodeBin = os.getenv('MOZ_NODE_PATH', None)
+        if not nodeBin:
+            self.log.info('MOZ_NODE_PATH environment variable not set')
+            return
 
-        if os.getenv('MOZ_ASSUME_NODE_RUNNING', None):
-            self.log.info('Assuming required node servers are already running')
-        elif nodeBin:
-            self.log.info('Found node at %s' % (nodeBin,))
+        if not os.path.exists(nodeBin) or not os.path.isfile(nodeBin):
+            self.log.error('node not found at MOZ_NODE_PATH %s' % (nodeBin))
+            return
+
+        self.log.info('Found node at %s' % (nodeBin,))
+
+        def startServer(name, serverJs):
+            if not os.path.exists(serverJs):
+                self.log.error('%s not found at %s' % (name, serverJs))
+                return
 
-            def startServer(name, serverJs):
-                if os.path.exists(serverJs):
-                    # OK, we found our server, let's try to get it running
-                    self.log.info('Found %s at %s' % (name, serverJs))
-                    try:
-                        # We pipe stdin to node because the server will exit when its
-                        # stdin reaches EOF
-                        process = Popen([nodeBin, serverJs], stdin=PIPE, stdout=PIPE,
-                                stderr=PIPE, env=self.env, cwd=os.getcwd())
-                        self.nodeProc[name] = process
+            # OK, we found our server, let's try to get it running
+            self.log.info('Found %s at %s' % (name, serverJs))
+            try:
+                # We pipe stdin to node because the server will exit when its
+                # stdin reaches EOF
+                process = Popen([nodeBin, serverJs], stdin=PIPE, stdout=PIPE,
+                        stderr=PIPE, env=self.env, cwd=os.getcwd())
+                self.nodeProc[name] = process
 
-                        # Check to make sure the server starts properly by waiting for it to
-                        # tell us it's started
-                        msg = process.stdout.readline()
-                        if 'server listening' in msg:
-                            searchObj = re.search( r'HTTP2 server listening on port (.*)', msg, 0)
-                            if searchObj:
-                              self.env["MOZHTTP2_PORT"] = searchObj.group(1)
-                    except OSError, e:
-                        # This occurs if the subprocess couldn't be started
-                        self.log.error('Could not run %s server: %s' % (name, str(e)))
+                # Check to make sure the server starts properly by waiting for it to
+                # tell us it's started
+                msg = process.stdout.readline()
+                if 'server listening' in msg:
+                    searchObj = re.search( r'HTTP2 server listening on port (.*)', msg, 0)
+                    if searchObj:
+                      self.env["MOZHTTP2_PORT"] = searchObj.group(1)
+            except OSError, e:
+                # This occurs if the subprocess couldn't be started
+                self.log.error('Could not run %s server: %s' % (name, str(e)))
 
-            myDir = os.path.split(os.path.abspath(__file__))[0]
-            startServer('moz-http2', os.path.join(myDir, 'moz-http2', 'moz-http2.js'))
+        myDir = os.path.split(os.path.abspath(__file__))[0]
+        startServer('moz-http2', os.path.join(myDir, 'moz-http2', 'moz-http2.js'))
 
     def shutdownNode(self):
         """
           Shut down our node process, if it exists
         """
         for name, proc in self.nodeProc.iteritems():
             self.log.info('Node %s server shutting down ...' % name)
             if proc.poll() is not None: