Commits

Robert Brewer committed 4b03669

New test and fix for errors during engine.start().

  • Participants
  • Parent commits b27597c

Comments (0)

Files changed (3)

File cherrypy/restsrv/wspbus.py

         """Start all services."""
         self.state = states.STARTING
         self.log('Bus starting')
-        self.publish('start')
+        try:
+            self.publish('start')
+        except:
+            try:
+                self.stop()
+            except:
+                # Any stop errors will be logged inside publish().
+                pass
+            raise
         self.state = states.STARTED
     
     def exit(self, status=0):

File cherrypy/test/test_states.py

         except OSError, x:
             if x.args != (10, 'No child processes'):
                 raise
+    
+    def test_5_Start_Error(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__),
+                                  "test_states_demo.py")
+        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.
+        args = [sys.executable, demoscript, host, str(port), '-starterror']
+        if self.scheme == "https":
+            args.append('-ssl')
+        exit_code = os.spawnl(os.P_WAIT, sys.executable, *args)
+        if exit_code == 0:
+            self.fail("Process failed to return nonzero exit code.")
 
 
 class DaemonizeTest(helper.CPWebCase):

File cherrypy/test/test_states_demo.py

     
     cherrypy.engine.subscribe('start', cherrypy.server.quickstart)
     
+    if '-starterror' in sys.argv[3:]:
+        cherrypy.engine.subscribe('start', lambda: 1/0)
+    
     # This is in a special order for a reason:
     # it allows test_states to wait_for_occupied_port
     # and then immediately call getPage without getting 503.