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

Changeset 2442

Show
Ignore:
Timestamp:
06/14/09 18:22:40
Author:
fumanchu
Message:

test_session bugfix, plus a couple tweaks.

Files:

Legend:

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

    r2437 r2442  
    5959     
    6060    def skip(self, msg='skipped '): 
    61         sys.stdout.write(msg) 
     61        sys.stderr.write(msg) 
    6262     
    6363    def assertErrorPage(self, status, message=None, pattern=''): 
  • trunk/cherrypy/test/test_session.py

    r2437 r2442  
    22test.prefer_parent_path() 
    33 
    4 import httplib 
     4from httplib import HTTPConnection, HTTPSConnection 
    55import os 
    66localDir = os.path.dirname(__file__) 
     
    5757            if hasattr(cherrypy, "session"): 
    5858                del cherrypy.session 
     59            cls = getattr(sessions, newtype.title() + 'Session') 
     60            if cls.clean_thread: 
     61                cls.clean_thread.stop() 
     62                cls.clean_thread.unsubscribe() 
     63                del cls.clean_thread 
    5964        setsessiontype.exposed = True 
    6065        setsessiontype._cp_config = {'tools.sessions.on': False} 
     
    107112         
    108113        def session_cookie(self): 
     114            # Must load() to start the clean thread. 
    109115            cherrypy.session.load() 
    110116            return cherrypy.session.id 
     
    222228        def request(index): 
    223229            if self.scheme == 'https': 
    224                 c = httplib.HTTPSConnection('%s:%s' % (self.interface(), self.PORT)) 
     230                c = HTTPSConnection('%s:%s' % (self.interface(), self.PORT)) 
    225231            else: 
    226                 c = httplib.HTTPConnection('%s:%s' % (self.interface(), self.PORT)) 
    227             for i in xrange(request_count): 
     232                c = HTTPConnection('%s:%s' % (self.interface(), self.PORT)) 
     233            for i in range(request_count): 
    228234                c.putrequest('GET', '/') 
    229235                for k, v in cookies: 
     
    242248        # <client_thread_count> concurrent clients 
    243249        ts = [] 
    244         for c in xrange(client_thread_count): 
     250        for c in range(client_thread_count): 
    245251            data_dict[c] = 0 
    246252            t = threading.Thread(target=request, args=(c,)) 
     
    307313    def test_7_session_cookies(self): 
    308314        self.getPage('/setsessiontype/ram') 
     315        self.getPage('/clear') 
    309316        self.getPage('/session_cookie') 
    310317        # grab the cookie ID 
     
    322329        self.assertBody(id1) 
    323330        self.assertEqual(sessions.RamSession.cache.keys(), [id1]) 
    324          
    325         # Wait 0.5 seconds to separate the two sessions 
    326         time.sleep(0.5) 
    327331         
    328332        # Simulate a browser close by just not sending the cookies 
     
    336340        self.assertNotEqual(id1, id2) 
    337341        self.assertEqual(set(sessions.RamSession.cache.keys()), set([id1, id2])) 
    338         # Wait for the session.timeout on the first session (1 second) 
    339         time.sleep(1) 
    340         cache = sessions.RamSession.cache.keys() 
    341         if cache != [id2]: 
    342             if set(cache) == set([id1, id2]): 
    343                 self.fail("The first session did not time out.") 
    344             elif not cache: 
    345                 self.fail("The second session may have been cleaned up " 
    346                           "prematurely, but it may just be thread timing.") 
    347             else: 
    348                 self.fail("Unknown session id in cache: %r", cache) 
    349         # Wait for the session.timeout on the second session (1 second) 
    350         time.sleep(1) 
     342         
     343        # Wait for the session.timeout on both sessions 
     344        time.sleep(2.5) 
    351345        cache = sessions.RamSession.cache.keys() 
    352346        if cache: 
     
    426420             
    427421            def request(index): 
    428                 for i in xrange(request_count): 
     422                for i in range(request_count): 
    429423                    self.getPage("/", cookies) 
    430424                    # Uncomment the following line to prove threads overlap. 
     
    437431            # each of <client_thread_count> clients 
    438432            ts = [] 
    439             for c in xrange(client_thread_count): 
     433            for c in range(client_thread_count): 
    440434                data_dict[c] = 0 
    441435                t = threading.Thread(target=request, args=(c,)) 

Hosted by WebFaction

Log in as guest/cpguest to create tickets