1 """Tests for managing HTTP issues (malformed requests, etc).
2
3 Some of these tests check timeouts, etcetera, and therefore take a long
4 time to run. Therefore, this module should probably not be included in
5 the 'comprehensive' test suite (test.py).
6 """
7
8 from cherrypy.test import test
9 test.prefer_parent_path()
10
11 import gc
12 import httplib
13 import threading
14 import cherrypy
15 from cherrypy import _cprequest
16
17
18 data = object()
19
21 return [x for x in gc.get_objects() if isinstance(x, cls)]
22
24
25 class Root:
26 def index(self, *args, **kwargs):
27 cherrypy.request.thing = data
28 return "Hello world!"
29 index.exposed = True
30
31 def gc_stats(self):
32 return "%s %s %s %s" % (gc.collect(),
33 len(get_instances(_cprequest.Request)),
34 len(get_instances(_cprequest.Response)),
35 len(gc.get_referrers(data)))
36 gc_stats.exposed = True
37 cherrypy.tree.mount(Root())
38 cherrypy.config.update({'environment': 'test_suite'})
39
40
41 from cherrypy.test import helper
42
52
53
55
60
61 ts = []
62 for _ in range(25):
63 t = threading.Thread(target=getpage)
64 ts.append(t)
65 t.start()
66
67 for t in ts:
68 t.join()
69
70 self.getPage("/gc_stats")
71 self.assertBody("0 1 1 1")
72
73
74 if __name__ == '__main__':
75 setup_server()
76 helper.testmain()
77