Download Install Tutorial Docs FAQ Tools WikiLicense Team IRC Planet Involvement Shop Book

Changeset 1457

Show
Ignore:
Timestamp:
11/29/06 14:07:14
Author:
fumanchu
Message:

More test_states fixes (getPage('/pid') would often return 503 Unavailable).

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/cherrypy/test/test_states.py

    r1451 r1457  
    228228     
    229229    def test_4_Autoreload(self): 
    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) 
    244263            cherrypy._cpserver.wait_for_occupied_port(host, port) 
    245264             
     265            self.getPage("/pid") 
     266            assert self.body.isdigit(), self.body 
     267            self.assertNotEqual(self.body, pid) 
     268            pid = self.body 
     269        finally: 
     270            # Shut down the spawned process 
     271            self.getPage("/stop") 
     272         
     273        try: 
    246274            try: 
    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 
    268283 
    269284db_connection = None 
  • trunk/cherrypy/test/test_states_demo.py

    r1451 r1457  
    3333        conf['server.ssl_private_key'] = serverpem 
    3434     
    35     cherrypy.quickstart(Root(), config={'global': conf}) 
     35    # This is in a special order for a reason: 
     36    # it allows test_states to wait_for_occupied_port 
     37    # and then immediately call getPage without getting 503. 
     38    cherrypy.config.update(conf) 
     39    cherrypy.tree.mount(Root(), config={'global': conf}) 
     40    cherrypy.engine.start(blocking=False) 
     41    cherrypy.server.quickstart() 
     42    cherrypy.engine.block() 

Hosted by WebFaction

Log in as guest/cpguest to create tickets