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

Changeset 1755

Show
Ignore:
Timestamp:
10/18/07 16:59:36
Author:
fumanchu
Message:

Some fixes to test_states.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/cherrypy/restsrv/plugins.py

    r1754 r1755  
    412412        self.threads = {} 
    413413        self.bus = bus 
     414        self.bus.listeners.setdefault('acquire_thread', set()) 
     415        self.bus.listeners.setdefault('release_thread', set()) 
    414416     
    415417    def acquire_thread(self): 
  • trunk/cherrypy/test/test_states.py

    r1743 r1755  
    1313engine = cherrypy.engine 
    1414thisdir = os.path.join(os.getcwd(), os.path.dirname(__file__)) 
    15 PID_file_path = os.path.join(thisdir,'pid_for_test_daemonize') 
     15PID_file_path = os.path.join(thisdir, 'pid_for_test_daemonize') 
     16 
    1617 
    1718class Root: 
     
    5051class Dependency: 
    5152     
    52     def __init__(self): 
     53    def __init__(self, bus): 
     54        self.bus = bus 
    5355        self.running = False 
    5456        self.startcount = 0 
     
    5658        self.threads = {} 
    5759     
     60    def subscribe(self): 
     61        self.bus.subscribe('start', self.start) 
     62        self.bus.subscribe('stop', self.stop) 
     63        self.bus.subscribe('graceful', self.graceful) 
     64        self.bus.subscribe('start_thread', self.startthread) 
     65        self.bus.subscribe('stop_thread', self.stopthread) 
     66     
    5867    def start(self): 
    5968        self.running = True 
     
    7180    def stopthread(self, thread_id): 
    7281        del self.threads[thread_id] 
     82 
     83db_connection = Dependency(engine) 
     84db_connection.subscribe() 
    7385 
    7486 
     
    219231        cherrypy.server.start() 
    220232        try: 
    221             self.assertNotEqual(cherrypy._timeout_monitor.thread, None) 
     233            self.assertNotEqual(cherrypy.timeout_monitor.thread, None) 
    222234             
    223235            # Request a "normal" page. 
    224             self.assertEqual(cherrypy._timeout_monitor.servings, []) 
     236            self.assertEqual(cherrypy.timeout_monitor.servings, []) 
    225237            self.getPage("/") 
    226238            self.assertBody("Hello World") 
    227239            # request.close is called async. 
    228             while cherrypy._timeout_monitor.servings: 
     240            while cherrypy.timeout_monitor.servings: 
    229241                print ".", 
    230242                time.sleep(0.01) 
     
    296308                raise 
    297309 
     310 
    298311class DaemonizeTest(helper.CPWebCase): 
    299     def test_0_Daemonize(self): 
     312     
     313    def test_Daemonize(self): 
    300314        if not self.server_class: 
    301315            print "skipped (no server) ", 
     
    304318            print "skipped (not on posix) ", 
    305319            return 
    306  
    307  
     320         
    308321        # Start the demo script in a new process 
    309322        demoscript = os.path.join(os.getcwd(), os.path.dirname(__file__), 
     
    321334        exit_code = os.spawnl(os.P_WAIT, sys.executable, *args) 
    322335        cherrypy._cpserver.wait_for_occupied_port(host, port) 
    323  
     336         
    324337        # Give the server some time to start up 
    325338        time.sleep(2) 
    326  
     339         
    327340        # Get the PID from the file. 
    328341        pid = int(open(PID_file_path).read()) 
     
    342355            if x.args != (10, 'No child processes'): 
    343356                raise 
    344  
     357         
    345358        # Wait until here to test the exit code because we want to ensure 
    346359        # that we wait for the daemon to finish running before we fail. 
    347360        if exit_code != 0: 
    348361            self.fail("Daemonized process failed to exit cleanly") 
    349 db_connection = None 
     362 
    350363 
    351364def run(server, conf): 
     
    356369    daemon_suite = helper.CPTestLoader.loadTestsFromTestCase(DaemonizeTest) 
    357370    try: 
    358         global db_connection 
    359         db_connection = Dependency() 
    360         engine.subscribe('start', db_connection.start) 
    361         engine.subscribe('stop', db_connection.stop) 
    362         engine.subscribe('graceful', db_connection.graceful) 
    363         engine.subscribe('start_thread', db_connection.startthread) 
    364         engine.subscribe('stop_thread', db_connection.stopthread) 
    365          
    366371        try: 
    367372            import pyconquer 
  • trunk/cherrypy/test/test_states_demo.py

    r1745 r1755  
    55 
    66import cherrypy 
    7 from cherrypy.restsrv.plugins import daemonize, PIDFile 
     7from cherrypy.restsrv import plugins 
    88thisdir = os.path.join(os.getcwd(), os.path.dirname(__file__)) 
    9 PID_file_path = os.path.join(thisdir,'pid_for_test_daemonize') 
     9PID_file_path = os.path.join(thisdir, 'pid_for_test_daemonize') 
     10 
    1011 
    1112class Root: 
     
    5556                raise SystemExit(1) 
    5657        sys.exitfunc = exitfunc 
    57  
    58         cherrypy.engine.subscribe('start', daemonize
    59         pid_file = PIDFile(cherrypy.engine, PID_file_path
    60  
     58         
     59        plugins.Daemonizer(cherrypy.engine).subscribe(
     60        plugins.PIDFile(cherrypy.engine, PID_file_path).subscribe(
     61     
    6162    cherrypy.engine.subscribe('start', cherrypy.server.quickstart)    
    62  
     63     
    6364    # This is in a special order for a reason: 
    6465    # it allows test_states to wait_for_occupied_port 

Hosted by WebFaction

Log in as guest/cpguest to create tickets