Mercurial > p > roundup > code
comparison test/test_liveserver.py @ 6747:d32d43e4a5ba
wsgi can cache tracker instance enabled by feature flag.
Patch by Marcus Priesch caches a loaded tracker instance and reuse it
for future client sessions.
It is enabled by a feature flag in wsgi.py since it arrived during the
2.2.0 beta period.
The provided wsgi.py is modified to enable it. Testing is run with
flag enabled and disabled.
Ralf Schlatterbeck and Marcus tested it on one of their larger more
complex trackers and it sped up the response time to a client request
by a factor of 3 (270ms down to about 80-85ms).
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Sat, 02 Jul 2022 14:04:00 -0400 |
| parents | 9a1f5e496e6c |
| children | be3fd5e9577e |
comparison
equal
deleted
inserted
replaced
| 6746:efa203f3c696 | 6747:d32d43e4a5ba |
|---|---|
| 36 import sys | 36 import sys |
| 37 | 37 |
| 38 _py3 = sys.version_info[0] > 2 | 38 _py3 = sys.version_info[0] > 2 |
| 39 | 39 |
| 40 @skip_requests | 40 @skip_requests |
| 41 class SimpleTest(LiveServerTestCase): | 41 class WsgiSetup(LiveServerTestCase): |
| 42 # have chicken and egg issue here. Need to encode the base_url | 42 # have chicken and egg issue here. Need to encode the base_url |
| 43 # in the config file but we don't know it until after | 43 # in the config file but we don't know it until after |
| 44 # the server is started and has read the config.ini. | 44 # the server is started and has read the config.ini. |
| 45 # so only allow one port number | 45 # so only allow one port number |
| 46 port_range = (9001, 9001) # default is (8080, 8090) | 46 port_range = (9001, 9001) # default is (8080, 8090) |
| 101 if error.errno not in (errno.ENOENT, errno.ESRCH): raise | 101 if error.errno not in (errno.ENOENT, errno.ESRCH): raise |
| 102 i18n.LOCALE_DIRS = cls.backup_locale_dirs | 102 i18n.LOCALE_DIRS = cls.backup_locale_dirs |
| 103 i18n.DOMAIN = cls.backup_domain | 103 i18n.DOMAIN = cls.backup_domain |
| 104 | 104 |
| 105 def create_app(self): | 105 def create_app(self): |
| 106 '''The wsgi app to start''' | 106 '''The wsgi app to start - no feature_flags set.''' |
| 107 | |
| 107 if _py3: | 108 if _py3: |
| 108 return validator(RequestDispatcher(self.dirname)) | 109 return validator(RequestDispatcher(self.dirname)) |
| 109 else: | 110 else: |
| 110 # wsgiref/validator.py InputWrapper::readline is broke and | 111 # wsgiref/validator.py InputWrapper::readline is broke and |
| 111 # doesn't support the max bytes to read argument. | 112 # doesn't support the max bytes to read argument. |
| 112 return RequestDispatcher(self.dirname) | 113 return RequestDispatcher(self.dirname) |
| 113 | 114 |
| 115 | |
| 116 class BaseTestCases(WsgiSetup): | |
| 117 """Class with all tests to run against wsgi server. Is reused when | |
| 118 wsgi server is started with various feature flags | |
| 119 """ | |
| 114 | 120 |
| 115 def test_start_page(self): | 121 def test_start_page(self): |
| 116 """ simple test that verifies that the server can serve a start page. | 122 """ simple test that verifies that the server can serve a start page. |
| 117 """ | 123 """ |
| 118 f = requests.get(self.url_base()) | 124 f = requests.get(self.url_base()) |
| 971 'Origin': "http://localhost:9001"} | 977 'Origin': "http://localhost:9001"} |
| 972 ) | 978 ) |
| 973 self.assertEqual(r.status_code, 201) | 979 self.assertEqual(r.status_code, 201) |
| 974 print(r.status_code) | 980 print(r.status_code) |
| 975 | 981 |
| 976 | 982 class TestFeatureFlagCacheTrackerOn(BaseTestCases, WsgiSetup): |
| 983 """Class to run all test in BaseTestCases with the cache_tracker | |
| 984 feature flag enabled when starting the wsgi server | |
| 985 """ | |
| 986 def create_app(self): | |
| 987 '''The wsgi app to start with feature flag enabled''' | |
| 988 ff = { "cache_tracker": "" } | |
| 989 if _py3: | |
| 990 return validator(RequestDispatcher(self.dirname, feature_flags=ff)) | |
| 991 else: | |
| 992 # wsgiref/validator.py InputWrapper::readline is broke and | |
| 993 # doesn't support the max bytes to read argument. | |
| 994 return RequestDispatcher(self.dirname, feature_flags=ff) |
