diff options
author | Graham Dumpleton <Graham.Dumpleton@gmail.com> | 2018-02-08 17:20:43 +1100 |
---|---|---|
committer | Graham Dumpleton <Graham.Dumpleton@gmail.com> | 2018-02-08 17:20:43 +1100 |
commit | 01133154dae6b8bf5457c2f38f793be9ff5d4225 (patch) | |
tree | 8439218951df774cff6c1f2d785c7601f1e7686c /tests/events.wsgi | |
parent | 53a878dc185a7be2a14fca1ef43fcf43b6b9c047 (diff) | |
download | mod_wsgi-01133154dae6b8bf5457c2f38f793be9ff5d4225.tar.gz |
Enhance test script for event subscriptions.
Diffstat (limited to 'tests/events.wsgi')
-rw-r--r-- | tests/events.wsgi | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/tests/events.wsgi b/tests/events.wsgi index ab3f10f..0504794 100644 --- a/tests/events.wsgi +++ b/tests/events.wsgi @@ -4,6 +4,7 @@ import mod_wsgi import traceback import time import os +import threading try: mod_wsgi.request_data() @@ -19,20 +20,29 @@ def wrapper(application): def event_handler(name, **kwargs): print('EVENT', name, kwargs, os.getpid(), mod_wsgi.application_group) if name == 'request_started': - request = mod_wsgi.request_data() + request = kwargs['request_data'] print('REQUEST', request) environ = kwargs['request_environ'] start_time = time.time() request['start_time'] = start_time + thread = threading.current_thread() + request['thread_name'] = thread.name + request['thread_id'] = thread.ident return dict(application_object=wrapper(kwargs['application_object'])) - elif name == 'request_finished': + elif name == 'response_started': request = mod_wsgi.request_data() + print('CONTENT', request) + print('ACTIVE', mod_wsgi.active_requests) + elif name == 'request_finished': + request = kwargs['request_data'] print('REQUEST', request) print('FINISH', time.time()-request['start_time']) print('PROCESS', mod_wsgi.process_metrics()) elif name == 'request_exception': - exc_info = kwargs['exc_info'] - traceback.print_exception(*exc_info) + exception_info = kwargs['exception_info'] + traceback.print_exception(*exception_info) + elif name == 'process_stopping': + print('SHUTDOWN', mod_wsgi.active_requests) print('EVENTS', mod_wsgi.event_callbacks) @@ -42,9 +52,11 @@ print('CALLBACKS', mod_wsgi.event_callbacks) def application(environ, start_response): failure_mode = environ.get('HTTP_X_FAILURE_MODE', '') - failure_mode = failure_mode.split() + sleep_duration = environ.get('HTTP_X_SLEEP_DURATION', 0) + sleep_duration = float(sleep_duration or 0) + if 'application' in failure_mode: raise RuntimeError('application') @@ -57,6 +69,9 @@ def application(environ, start_response): environ['wsgi.input'].read() + if sleep_duration: + time.sleep(sleep_duration) + try: yield output |