Anonymous committed 372d805

Adding a unit test which exposes a bug whereby CP exit codes are mistakenly set to 0 by Daemonizer even if there are pending startup errors waiting to be raised.

Comments (0)

Files changed (2)


         if exit_code == 0:
   "Process failed to return nonzero exit code.")
+    def test_6_Start_Error_With_Daemonize(self):
+        if not self.server_class:
+            print "skipped (no server) ",
+            return
+        # Start the demo script in a new process
+        demoscript = os.path.join(os.getcwd(), os.path.dirname(__file__),
+                                  "")
+        host = cherrypy.server.socket_host
+        port = cherrypy.server.socket_port
+        # If a process errors during start, it should stop the engine
+        # and exit with a non-zero exit code, even if we daemonize soon
+        # thereafter.
+        args = [sys.executable, demoscript, host, str(port), '-starterror', '-daemonize']
+        if self.scheme == "https":
+            args.append('-ssl')
+        exit_code = os.spawnl(os.P_WAIT, sys.executable, *args)
+        if exit_code == 0:
+  "Process failed to return nonzero exit code.")
+        time.sleep(2) # Wait for the daemonized process to exit.
 class DaemonizeTest(helper.CPWebCase):


     conf = {"server.socket_host": sys.argv[1],
             "server.socket_port": int(sys.argv[2]),
             "log.screen": False,
+            "log.error_file": os.path.join(thisdir, 'test_states_demo.error.log'),
     if '-ssl' in sys.argv[3:]:
         plugins.PIDFile(cherrypy.engine, PID_file_path).subscribe()
-    cherrypy.engine.subscribe('start', cherrypy.server.quickstart)
+    cherrypy.engine.subscribe('start', cherrypy.server.quickstart, priority=75)
     if '-starterror' in sys.argv[3:]:
-        cherrypy.engine.subscribe('start', lambda: 1/0)
+        cherrypy.engine.subscribe('start', lambda: 1/0, priority=6)
     # This is in a special order for a reason:
     # it allows test_states to wait_for_occupied_port
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.