20
20
21
21
from newrelic .packages import six
22
22
23
+ from conftest import async_handler_support , skip_if_not_async_handler_support
24
+
23
25
try :
24
26
# The __version__ attribute was only added in 0.7.0.
25
27
# Flask team does not use semantic versioning during development.
@@ -48,7 +50,10 @@ def target_application():
48
50
# functions are different between Python 2 and 3, with the latter
49
51
# showing <local> scope in path.
50
52
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
52
57
return _test_application
53
58
54
59
@@ -87,7 +92,6 @@ def target_application():
87
92
('FunctionNode' , []),
88
93
)
89
94
90
-
91
95
@validate_transaction_errors (errors = [])
92
96
@validate_transaction_metrics ('_test_application:index_page' ,
93
97
scoped_metrics = _test_application_index_scoped_metrics )
@@ -97,6 +101,23 @@ def test_application_index():
97
101
response = application .get ('/index' )
98
102
response .mustcontain ('INDEX RESPONSE' )
99
103
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' )
100
121
101
122
_test_application_endpoint_scoped_metrics = [
102
123
('Function/flask.app:Flask.wsgi_app' , 1 ),
@@ -107,7 +128,6 @@ def test_application_index():
107
128
('Function/werkzeug.wsgi:ClosingIterator.close' , 1 )]
108
129
109
130
110
- @requires_endpoint_decorator
111
131
@validate_transaction_errors (errors = [])
112
132
@validate_transaction_metrics ('_test_application:endpoint_page' ,
113
133
scoped_metrics = _test_application_endpoint_scoped_metrics )
@@ -124,11 +144,10 @@ def test_application_endpoint():
124
144
('Python/WSGI/Finalize' , 1 ),
125
145
('Function/_test_application:error_page' , 1 ),
126
146
('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 )]
128
150
129
- if is_gt_flask060 :
130
- _test_application_error_scoped_metrics .extend ([
131
- ('Function/flask.app:Flask.handle_user_exception' , 1 )])
132
151
133
152
if six .PY3 :
134
153
_test_application_error_errors = ['builtins:RuntimeError' ]
@@ -151,11 +170,8 @@ def test_application_error():
151
170
('Python/WSGI/Finalize' , 1 ),
152
171
('Function/_test_application:abort_404_page' , 1 ),
153
172
('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 )]
159
175
160
176
161
177
@validate_transaction_errors (errors = [])
@@ -173,11 +189,8 @@ def test_application_abort_404():
173
189
('Python/WSGI/Finalize' , 1 ),
174
190
('Function/_test_application:exception_404_page' , 1 ),
175
191
('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 )]
181
194
182
195
183
196
@validate_transaction_errors (errors = [])
@@ -194,11 +207,8 @@ def test_application_exception_404():
194
207
('Python/WSGI/Response' , 1 ),
195
208
('Python/WSGI/Finalize' , 1 ),
196
209
('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 )]
202
212
203
213
204
214
@validate_transaction_errors (errors = [])
@@ -235,11 +245,8 @@ def test_application_render_template_string():
235
245
('Python/WSGI/Finalize' , 1 ),
236
246
('Function/_test_application:template_not_found' , 1 ),
237
247
('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 )]
243
250
244
251
245
252
@validate_transaction_errors (errors = ['jinja2.exceptions:TemplateNotFound' ])
0 commit comments