1212# See the License for the specific language governing permissions and
1313# limitations under the License.
1414
15+ import json
16+
1517import pytest
1618from testing_support .fixtures import (
19+ reset_core_stats_engine ,
20+ validate_error_event_attributes_outside_transaction ,
1721 validate_transaction_errors ,
1822 validate_transaction_metrics ,
19- validate_error_event_attributes_outside_transaction ,
20- reset_core_stats_engine ,
2123)
2224
2325from newrelic .api .background_task import background_task
24- from newrelic .packages import six
25-
2626from newrelic .common .object_names import callable_name
27+ from newrelic .packages import six
2728
28- import json
2929
3030def test_serialization_metrics (skip_if_not_serializing , topic , send_producer_message ):
3131 txn_name = "test_serialization:test_serialization_metrics.<locals>.test" if six .PY3 else "test_serialization:test"
@@ -48,10 +48,13 @@ def test():
4848 test ()
4949
5050
51- @pytest .mark .parametrize ("key,value" , (
52- (object (), "A" ),
53- ("A" , object ()),
54- ))
51+ @pytest .mark .parametrize (
52+ "key,value" ,
53+ (
54+ (object (), "A" ),
55+ ("A" , object ()),
56+ ),
57+ )
5558def test_serialization_errors (skip_if_not_serializing , topic , producer , key , value ):
5659 error_cls = TypeError
5760
@@ -64,13 +67,16 @@ def test():
6467 test ()
6568
6669
67- @pytest .mark .parametrize ("key,value" , (
68- (b"%" , b"{}" ),
69- (b"{}" , b"%" ),
70- ))
70+ @pytest .mark .parametrize (
71+ "key,value" ,
72+ (
73+ (b"%" , b"{}" ),
74+ (b"{}" , b"%" ),
75+ ),
76+ )
7177def test_deserialization_errors (skip_if_not_serializing , monkeypatch , topic , producer , consumer , key , value ):
7278 error_cls = json .decoder .JSONDecodeError if six .PY3 else ValueError
73-
79+
7480 # Remove serializers to cause intentional issues
7581 monkeypatch .setitem (producer .config , "value_serializer" , None )
7682 monkeypatch .setitem (producer .config , "key_serializer" , None )
@@ -80,13 +86,16 @@ def test_deserialization_errors(skip_if_not_serializing, monkeypatch, topic, pro
8086
8187 @reset_core_stats_engine ()
8288 @validate_error_event_attributes_outside_transaction (
83- num_errors = 1 ,
84- exact_attrs = {"intrinsic" : {"error.class" : callable_name (error_cls )}, "agent" : {}, "user" : {}}
89+ num_errors = 1 , exact_attrs = {"intrinsic" : {"error.class" : callable_name (error_cls )}, "agent" : {}, "user" : {}}
8590 )
8691 def test ():
8792 with pytest .raises (error_cls ):
88- for record in consumer :
89- pass
90- assert record is not None , "No record consumed."
93+ timeout = 10
94+ attempts = 0
95+ record = None
96+ while not record and attempts < timeout :
97+ for record in consumer :
98+ pass
99+ attempts += 1
91100
92101 test ()
0 commit comments