| 230 | | if self.server_class: |
|---|
| 231 | | demoscript = os.path.join(os.getcwd(), os.path.dirname(__file__), |
|---|
| 232 | | "test_states_demo.py") |
|---|
| 233 | | |
|---|
| 234 | | # Start the demo script in a new process |
|---|
| 235 | | host = cherrypy.server.socket_host |
|---|
| 236 | | port = cherrypy.server.socket_port |
|---|
| 237 | | cherrypy._cpserver.wait_for_free_port(host, port) |
|---|
| 238 | | if self.scheme == "https": |
|---|
| 239 | | os.spawnl(os.P_NOWAIT, sys.executable, sys.executable, |
|---|
| 240 | | demoscript, host, str(port), '-ssl') |
|---|
| 241 | | else: |
|---|
| 242 | | os.spawnl(os.P_NOWAIT, sys.executable, sys.executable, |
|---|
| 243 | | demoscript, host, str(port)) |
|---|
| | 230 | if not self.server_class: |
|---|
| | 231 | print "skipped (no server) ", |
|---|
| | 232 | return |
|---|
| | 233 | |
|---|
| | 234 | # Start the demo script in a new process |
|---|
| | 235 | demoscript = os.path.join(os.getcwd(), os.path.dirname(__file__), |
|---|
| | 236 | "test_states_demo.py") |
|---|
| | 237 | host = cherrypy.server.socket_host |
|---|
| | 238 | port = cherrypy.server.socket_port |
|---|
| | 239 | cherrypy._cpserver.wait_for_free_port(host, port) |
|---|
| | 240 | |
|---|
| | 241 | args = [sys.executable, demoscript, host, str(port)] |
|---|
| | 242 | if self.scheme == "https": |
|---|
| | 243 | args.append('-ssl') |
|---|
| | 244 | pid = os.spawnl(os.P_NOWAIT, sys.executable, *args) |
|---|
| | 245 | pid = str(pid) |
|---|
| | 246 | cherrypy._cpserver.wait_for_occupied_port(host, port) |
|---|
| | 247 | |
|---|
| | 248 | try: |
|---|
| | 249 | self.getPage("/pid") |
|---|
| | 250 | assert self.body.isdigit(), self.body |
|---|
| | 251 | pid = self.body |
|---|
| | 252 | |
|---|
| | 253 | # Give the autoreloader time to cache the file time. |
|---|
| | 254 | time.sleep(2) |
|---|
| | 255 | |
|---|
| | 256 | # Touch the file |
|---|
| | 257 | f = open(demoscript, 'ab') |
|---|
| | 258 | f.write(" ") |
|---|
| | 259 | f.close() |
|---|
| | 260 | |
|---|
| | 261 | # Give the autoreloader time to re-exec the process |
|---|
| | 262 | time.sleep(2) |
|---|
| 247 | | self.getPage("/pid") |
|---|
| 248 | | pid = self.body |
|---|
| 249 | | |
|---|
| 250 | | # Give the autoreloader time to cache the file time. |
|---|
| 251 | | time.sleep(2) |
|---|
| 252 | | |
|---|
| 253 | | # Touch the file |
|---|
| 254 | | f = open(demoscript, 'ab') |
|---|
| 255 | | f.write(" ") |
|---|
| 256 | | f.close() |
|---|
| 257 | | |
|---|
| 258 | | # Give the autoreloader time to re-exec the process |
|---|
| 259 | | time.sleep(2) |
|---|
| 260 | | cherrypy._cpserver.wait_for_occupied_port(host, port) |
|---|
| 261 | | |
|---|
| 262 | | self.getPage("/pid") |
|---|
| 263 | | self.assertNotEqual(self.body, pid) |
|---|
| 264 | | finally: |
|---|
| 265 | | # Shut down the spawned process |
|---|
| 266 | | self.getPage("/stop") |
|---|
| 267 | | |
|---|
| | 275 | # Mac, UNIX |
|---|
| | 276 | print os.wait() |
|---|
| | 277 | except AttributeError: |
|---|
| | 278 | # Windows |
|---|
| | 279 | print os.waitpid(int(pid), 0) |
|---|
| | 280 | except OSError, x: |
|---|
| | 281 | if x.args != (10, 'No child processes'): |
|---|
| | 282 | raise |
|---|