Changeset 2442
- Timestamp:
- 06/14/09 18:22:40
- Files:
-
- trunk/cherrypy/test/helper.py (modified) (1 diff)
- trunk/cherrypy/test/test_session.py (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/cherrypy/test/helper.py
r2437 r2442 59 59 60 60 def skip(self, msg='skipped '): 61 sys.std out.write(msg)61 sys.stderr.write(msg) 62 62 63 63 def assertErrorPage(self, status, message=None, pattern=''): trunk/cherrypy/test/test_session.py
r2437 r2442 2 2 test.prefer_parent_path() 3 3 4 import httplib 4 from httplib import HTTPConnection, HTTPSConnection 5 5 import os 6 6 localDir = os.path.dirname(__file__) … … 57 57 if hasattr(cherrypy, "session"): 58 58 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 59 64 setsessiontype.exposed = True 60 65 setsessiontype._cp_config = {'tools.sessions.on': False} … … 107 112 108 113 def session_cookie(self): 114 # Must load() to start the clean thread. 109 115 cherrypy.session.load() 110 116 return cherrypy.session.id … … 222 228 def request(index): 223 229 if self.scheme == 'https': 224 c = httplib.HTTPSConnection('%s:%s' % (self.interface(), self.PORT))230 c = HTTPSConnection('%s:%s' % (self.interface(), self.PORT)) 225 231 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): 228 234 c.putrequest('GET', '/') 229 235 for k, v in cookies: … … 242 248 # <client_thread_count> concurrent clients 243 249 ts = [] 244 for c in xrange(client_thread_count):250 for c in range(client_thread_count): 245 251 data_dict[c] = 0 246 252 t = threading.Thread(target=request, args=(c,)) … … 307 313 def test_7_session_cookies(self): 308 314 self.getPage('/setsessiontype/ram') 315 self.getPage('/clear') 309 316 self.getPage('/session_cookie') 310 317 # grab the cookie ID … … 322 329 self.assertBody(id1) 323 330 self.assertEqual(sessions.RamSession.cache.keys(), [id1]) 324 325 # Wait 0.5 seconds to separate the two sessions326 time.sleep(0.5)327 331 328 332 # Simulate a browser close by just not sending the cookies … … 336 340 self.assertNotEqual(id1, id2) 337 341 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) 351 345 cache = sessions.RamSession.cache.keys() 352 346 if cache: … … 426 420 427 421 def request(index): 428 for i in xrange(request_count):422 for i in range(request_count): 429 423 self.getPage("/", cookies) 430 424 # Uncomment the following line to prove threads overlap. … … 437 431 # each of <client_thread_count> clients 438 432 ts = [] 439 for c in xrange(client_thread_count):433 for c in range(client_thread_count): 440 434 data_dict[c] = 0 441 435 t = threading.Thread(target=request, args=(c,))

