Changeset 709
- Timestamp:
- 10/03/05 12:01:29
- Files:
-
- trunk/cherrypy/_cpserver.py (modified) (2 diffs)
- trunk/cherrypy/_cputil.py (modified) (previous)
- trunk/cherrypy/test/test_states.py (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/cherrypy/_cpserver.py
r704 r709 222 222 """Stop, including any HTTP servers.""" 223 223 self.stop_http_server() 224 225 for thread_ident, i in seen_threads.iteritems(): 226 for func in self.onStopThreadList: 227 func(i) 228 seen_threads.clear() 229 230 for func in self.onStopServerList: 231 func() 232 224 233 self.state = STOPPED 225 234 cherrypy.log("CherryPy shut down", "HTTP") … … 235 244 httpstop() 236 245 cherrypy.log("HTTP Server shut down", "HTTP") 237 238 for thread_ident, i in seen_threads.iteritems():239 for func in self.onStopThreadList:240 func(i)241 seen_threads.clear()242 243 for func in self.onStopServerList:244 func()245 246 246 247 self.httpserver = None trunk/cherrypy/test/test_states.py
r699 r709 55 55 }) 56 56 57 class Dependency: 58 59 def __init__(self): 60 self.running = False 61 self.startcount = 0 62 self.threads = {} 63 64 def start(self): 65 self.running = True 66 self.startcount += 1 67 68 def stop(self): 69 self.running = False 70 71 def startthread(self, thread_id): 72 self.threads[thread_id] = None 73 74 def stopthread(self, thread_id): 75 del self.threads[thread_id] 76 57 77 58 78 import helper 59 60 79 61 80 class ServerStateTests(helper.CPWebCase): … … 66 85 self.assertRaises(cherrypy.NotReady, self.getPage, "/") 67 86 87 # And our db_connection should not be running 88 self.assertEqual(db_connection.running, False) 89 self.assertEqual(db_connection.startcount, 0) 90 self.assertEqual(len(db_connection.threads), 0) 91 68 92 # Test server start 69 93 cherrypy.server.start(True, self.serverClass) … … 75 99 self.assertRaises(IOError, cherrypy._cpserver.check_port, host, port) 76 100 101 # The db_connection should be running now 102 self.assertEqual(db_connection.running, True) 103 self.assertEqual(db_connection.startcount, 1) 104 self.assertEqual(len(db_connection.threads), 0) 105 77 106 self.getPage("/") 78 107 self.assertBody("Hello World") 108 self.assertEqual(len(db_connection.threads), 1) 79 109 80 110 # Test server stop … … 84 114 # Once the server has stopped, we should get a NotReady error again. 85 115 self.assertRaises(cherrypy.NotReady, self.getPage, "/") 116 117 # Verify that the onStopServer function was called 118 self.assertEqual(db_connection.running, False) 119 self.assertEqual(len(db_connection.threads), 0) 86 120 87 121 def test_1_Restart(self): 88 # Test server start89 122 cherrypy.server.start(True, self.serverClass) 123 124 # The db_connection should be running now 125 self.assertEqual(db_connection.running, True) 126 sc = db_connection.startcount 127 90 128 self.getPage("/") 91 129 self.assertBody("Hello World") 130 self.assertEqual(len(db_connection.threads), 1) 92 131 93 132 # Test server restart from this thread … … 96 135 self.getPage("/") 97 136 self.assertBody("Hello World") 137 self.assertEqual(db_connection.running, True) 138 self.assertEqual(db_connection.startcount, sc + 1) 139 self.assertEqual(len(db_connection.threads), 1) 98 140 99 141 # Test server restart from inside a page handler … … 101 143 self.assertEqual(cherrypy.server.state, 1) 102 144 self.assertBody("app was restarted succesfully") 145 self.assertEqual(db_connection.running, True) 146 self.assertEqual(db_connection.startcount, sc + 2) 147 # Since we are requesting synchronously, is only one thread used? 148 # Note that the "/restart" request has been flushed. 149 self.assertEqual(len(db_connection.threads), 0) 103 150 104 151 cherrypy.server.stop() 105 152 self.assertEqual(cherrypy.server.state, 0) 153 self.assertEqual(db_connection.running, False) 154 self.assertEqual(len(db_connection.threads), 0) 106 155 107 156 def test_2_KeyboardInterrupt(self): … … 120 169 self.assertEqual(cherrypy.server.state, 0) 121 170 self.assertRaises(cherrypy.NotReady, self.getPage, "/") 171 self.assertEqual(db_connection.running, False) 172 self.assertEqual(len(db_connection.threads), 0) 122 173 123 174 # Raise a keyboard interrupt in a page handler; on multithreaded … … 136 187 self.assertEqual(cherrypy.server.state, 0) 137 188 self.assertRaises(cherrypy.NotReady, self.getPage, "/") 138 189 self.assertEqual(db_connection.running, False) 190 self.assertEqual(len(db_connection.threads), 0) 191 192 193 db_connection = None 139 194 140 195 def run(server, conf): … … 143 198 suite = helper.CPTestLoader.loadTestsFromTestCase(ServerStateTests) 144 199 try: 200 global db_connection 201 db_connection = Dependency() 202 cherrypy.server.onStartServerList.append(db_connection.start) 203 cherrypy.server.onStopServerList.append(db_connection.stop) 204 cherrypy.server.onStartThreadList.append(db_connection.startthread) 205 cherrypy.server.onStopThreadList.append(db_connection.stopthread) 206 145 207 helper.CPTestRunner.run(suite) 146 208 finally:

