Robert Brewer avatar Robert Brewer committed 4b03669

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

Comments (0)

Files changed (3)

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):

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):

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.
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 ProjectModifiedEvent.java.
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.