2020
2121from newrelic .packages import six
2222
23+ from conftest import async_handler_support , skip_if_not_async_handler_support
24+
2325try :
2426 # The __version__ attribute was only added in 0.7.0.
2527 # Flask team does not use semantic versioning during development.
@@ -48,7 +50,10 @@ def target_application():
4850 # functions are different between Python 2 and 3, with the latter
4951 # showing <local> scope in path.
5052
51- from _test_application import _test_application
53+ if not async_handler_support :
54+ from _test_application import _test_application
55+ else :
56+ from _test_application_async import _test_application
5257 return _test_application
5358
5459
@@ -87,7 +92,6 @@ def target_application():
8792 ('FunctionNode' , []),
8893 )
8994
90-
9195@validate_transaction_errors (errors = [])
9296@validate_transaction_metrics ('_test_application:index_page' ,
9397 scoped_metrics = _test_application_index_scoped_metrics )
@@ -97,6 +101,23 @@ def test_application_index():
97101 response = application .get ('/index' )
98102 response .mustcontain ('INDEX RESPONSE' )
99103
104+ _test_application_async_scoped_metrics = [
105+ ('Function/flask.app:Flask.wsgi_app' , 1 ),
106+ ('Python/WSGI/Application' , 1 ),
107+ ('Python/WSGI/Response' , 1 ),
108+ ('Python/WSGI/Finalize' , 1 ),
109+ ('Function/_test_application_async:async_page' , 1 ),
110+ ('Function/werkzeug.wsgi:ClosingIterator.close' , 1 )]
111+
112+ @skip_if_not_async_handler_support
113+ @validate_transaction_errors (errors = [])
114+ @validate_transaction_metrics ('_test_application_async:async_page' ,
115+ scoped_metrics = _test_application_async_scoped_metrics )
116+ @validate_tt_parenting (_test_application_index_tt_parenting )
117+ def test_application_async ():
118+ application = target_application ()
119+ response = application .get ('/async' )
120+ response .mustcontain ('ASYNC RESPONSE' )
100121
101122_test_application_endpoint_scoped_metrics = [
102123 ('Function/flask.app:Flask.wsgi_app' , 1 ),
@@ -107,7 +128,6 @@ def test_application_index():
107128 ('Function/werkzeug.wsgi:ClosingIterator.close' , 1 )]
108129
109130
110- @requires_endpoint_decorator
111131@validate_transaction_errors (errors = [])
112132@validate_transaction_metrics ('_test_application:endpoint_page' ,
113133 scoped_metrics = _test_application_endpoint_scoped_metrics )
@@ -124,11 +144,10 @@ def test_application_endpoint():
124144 ('Python/WSGI/Finalize' , 1 ),
125145 ('Function/_test_application:error_page' , 1 ),
126146 ('Function/flask.app:Flask.handle_exception' , 1 ),
127- ('Function/werkzeug.wsgi:ClosingIterator.close' , 1 )]
147+ ('Function/werkzeug.wsgi:ClosingIterator.close' , 1 ),
148+ ('Function/flask.app:Flask.handle_user_exception' , 1 ),
149+ ('Function/flask.app:Flask.handle_user_exception' , 1 )]
128150
129- if is_gt_flask060 :
130- _test_application_error_scoped_metrics .extend ([
131- ('Function/flask.app:Flask.handle_user_exception' , 1 )])
132151
133152if six .PY3 :
134153 _test_application_error_errors = ['builtins:RuntimeError' ]
@@ -151,11 +170,8 @@ def test_application_error():
151170 ('Python/WSGI/Finalize' , 1 ),
152171 ('Function/_test_application:abort_404_page' , 1 ),
153172 ('Function/flask.app:Flask.handle_http_exception' , 1 ),
154- ('Function/werkzeug.wsgi:ClosingIterator.close' , 1 )]
155-
156- if is_gt_flask060 :
157- _test_application_abort_404_scoped_metrics .extend ([
158- ('Function/flask.app:Flask.handle_user_exception' , 1 )])
173+ ('Function/werkzeug.wsgi:ClosingIterator.close' , 1 ),
174+ ('Function/flask.app:Flask.handle_user_exception' , 1 )]
159175
160176
161177@validate_transaction_errors (errors = [])
@@ -173,11 +189,8 @@ def test_application_abort_404():
173189 ('Python/WSGI/Finalize' , 1 ),
174190 ('Function/_test_application:exception_404_page' , 1 ),
175191 ('Function/flask.app:Flask.handle_http_exception' , 1 ),
176- ('Function/werkzeug.wsgi:ClosingIterator.close' , 1 )]
177-
178- if is_gt_flask060 :
179- _test_application_exception_404_scoped_metrics .extend ([
180- ('Function/flask.app:Flask.handle_user_exception' , 1 )])
192+ ('Function/werkzeug.wsgi:ClosingIterator.close' , 1 ),
193+ ('Function/flask.app:Flask.handle_user_exception' , 1 )]
181194
182195
183196@validate_transaction_errors (errors = [])
@@ -194,11 +207,8 @@ def test_application_exception_404():
194207 ('Python/WSGI/Response' , 1 ),
195208 ('Python/WSGI/Finalize' , 1 ),
196209 ('Function/flask.app:Flask.handle_http_exception' , 1 ),
197- ('Function/werkzeug.wsgi:ClosingIterator.close' , 1 )]
198-
199- if is_gt_flask060 :
200- _test_application_not_found_scoped_metrics .extend ([
201- ('Function/flask.app:Flask.handle_user_exception' , 1 )])
210+ ('Function/werkzeug.wsgi:ClosingIterator.close' , 1 ),
211+ ('Function/flask.app:Flask.handle_user_exception' , 1 )]
202212
203213
204214@validate_transaction_errors (errors = [])
@@ -235,11 +245,8 @@ def test_application_render_template_string():
235245 ('Python/WSGI/Finalize' , 1 ),
236246 ('Function/_test_application:template_not_found' , 1 ),
237247 ('Function/flask.app:Flask.handle_exception' , 1 ),
238- ('Function/werkzeug.wsgi:ClosingIterator.close' , 1 )]
239-
240- if is_gt_flask060 :
241- _test_application_render_template_not_found_scoped_metrics .extend ([
242- ('Function/flask.app:Flask.handle_user_exception' , 1 )])
248+ ('Function/werkzeug.wsgi:ClosingIterator.close' , 1 ),
249+ ('Function/flask.app:Flask.handle_user_exception' , 1 )]
243250
244251
245252@validate_transaction_errors (errors = ['jinja2.exceptions:TemplateNotFound' ])
0 commit comments