13
13
except ImportError :
14
14
import mock # python < 3.3
15
15
16
+ try :
17
+ import gevent
18
+ except ImportError :
19
+ gevent = None
20
+
21
+
22
+ minimum_python_37_with_gevent = pytest .mark .skipif (
23
+ gevent and sys .version_info < (3 , 7 ),
24
+ reason = "Require Python 3.7 or higher with gevent" ,
25
+ )
26
+
16
27
17
28
def parse_metrics (bytes ):
18
29
rv = []
@@ -45,6 +56,7 @@ def parse_metrics(bytes):
45
56
return rv
46
57
47
58
59
+ @minimum_python_37_with_gevent
48
60
@pytest .mark .forked
49
61
def test_incr (sentry_init , capture_envelopes , maybe_monkeypatched_threading ):
50
62
sentry_init (
@@ -97,6 +109,7 @@ def test_incr(sentry_init, capture_envelopes, maybe_monkeypatched_threading):
97
109
}
98
110
99
111
112
+ @minimum_python_37_with_gevent
100
113
@pytest .mark .forked
101
114
def test_timing (sentry_init , capture_envelopes , maybe_monkeypatched_threading ):
102
115
sentry_init (
@@ -157,6 +170,7 @@ def test_timing(sentry_init, capture_envelopes, maybe_monkeypatched_threading):
157
170
)
158
171
159
172
173
+ @minimum_python_37_with_gevent
160
174
@pytest .mark .forked
161
175
def test_timing_decorator (
162
176
sentry_init , capture_envelopes , maybe_monkeypatched_threading
@@ -252,6 +266,7 @@ def amazing_nano():
252
266
assert line .strip () == "assert amazing() == 42"
253
267
254
268
269
+ @minimum_python_37_with_gevent
255
270
@pytest .mark .forked
256
271
def test_timing_basic (sentry_init , capture_envelopes , maybe_monkeypatched_threading ):
257
272
sentry_init (
@@ -306,6 +321,7 @@ def test_timing_basic(sentry_init, capture_envelopes, maybe_monkeypatched_thread
306
321
}
307
322
308
323
324
+ @minimum_python_37_with_gevent
309
325
@pytest .mark .forked
310
326
def test_distribution (sentry_init , capture_envelopes , maybe_monkeypatched_threading ):
311
327
sentry_init (
@@ -368,6 +384,7 @@ def test_distribution(sentry_init, capture_envelopes, maybe_monkeypatched_thread
368
384
)
369
385
370
386
387
+ @minimum_python_37_with_gevent
371
388
@pytest .mark .forked
372
389
def test_set (sentry_init , capture_envelopes , maybe_monkeypatched_threading ):
373
390
sentry_init (
@@ -421,6 +438,7 @@ def test_set(sentry_init, capture_envelopes, maybe_monkeypatched_threading):
421
438
}
422
439
423
440
441
+ @minimum_python_37_with_gevent
424
442
@pytest .mark .forked
425
443
def test_gauge (sentry_init , capture_envelopes , maybe_monkeypatched_threading ):
426
444
sentry_init (
@@ -454,6 +472,7 @@ def test_gauge(sentry_init, capture_envelopes, maybe_monkeypatched_threading):
454
472
}
455
473
456
474
475
+ @minimum_python_37_with_gevent
457
476
@pytest .mark .forked
458
477
def test_multiple (sentry_init , capture_envelopes ):
459
478
sentry_init (
@@ -508,6 +527,7 @@ def test_multiple(sentry_init, capture_envelopes):
508
527
}
509
528
510
529
530
+ @minimum_python_37_with_gevent
511
531
@pytest .mark .forked
512
532
def test_transaction_name (
513
533
sentry_init , capture_envelopes , maybe_monkeypatched_threading
@@ -548,6 +568,7 @@ def test_transaction_name(
548
568
}
549
569
550
570
571
+ @minimum_python_37_with_gevent
551
572
@pytest .mark .forked
552
573
@pytest .mark .parametrize ("sample_rate" , [1.0 , None ])
553
574
def test_metric_summaries (
@@ -658,6 +679,7 @@ def test_metric_summaries(
658
679
}
659
680
660
681
682
+ @minimum_python_37_with_gevent
661
683
@pytest .mark .forked
662
684
def test_metrics_summary_disabled (
663
685
sentry_init , capture_envelopes , maybe_monkeypatched_threading
@@ -702,6 +724,7 @@ def test_metrics_summary_disabled(
702
724
assert "_metrics_summary" not in t ["spans" ][0 ]
703
725
704
726
727
+ @minimum_python_37_with_gevent
705
728
@pytest .mark .forked
706
729
def test_metrics_summary_filtered (
707
730
sentry_init , capture_envelopes , maybe_monkeypatched_threading
@@ -771,6 +794,7 @@ def should_summarize_metric(key, tags):
771
794
} in t ["d:foo@second" ]
772
795
773
796
797
+ @minimum_python_37_with_gevent
774
798
@pytest .mark .forked
775
799
def test_tag_normalization (
776
800
sentry_init , capture_envelopes , maybe_monkeypatched_threading
@@ -818,6 +842,7 @@ def test_tag_normalization(
818
842
# fmt: on
819
843
820
844
845
+ @minimum_python_37_with_gevent
821
846
@pytest .mark .forked
822
847
def test_before_emit_metric (
823
848
sentry_init , capture_envelopes , maybe_monkeypatched_threading
@@ -861,6 +886,7 @@ def before_emit(key, tags):
861
886
}
862
887
863
888
889
+ @minimum_python_37_with_gevent
864
890
@pytest .mark .forked
865
891
def test_aggregator_flush (
866
892
sentry_init , capture_envelopes , maybe_monkeypatched_threading
@@ -881,6 +907,7 @@ def test_aggregator_flush(
881
907
assert Hub .current .client .metrics_aggregator .buckets == {}
882
908
883
909
910
+ @minimum_python_37_with_gevent
884
911
@pytest .mark .forked
885
912
def test_tag_serialization (
886
913
sentry_init , capture_envelopes , maybe_monkeypatched_threading
@@ -921,6 +948,7 @@ def test_tag_serialization(
921
948
}
922
949
923
950
951
+ @minimum_python_37_with_gevent
924
952
@pytest .mark .forked
925
953
def test_flush_recursion_protection (
926
954
sentry_init , capture_envelopes , monkeypatch , maybe_monkeypatched_threading
@@ -953,11 +981,12 @@ def bad_capture_envelope(*args, **kwargs):
953
981
assert m [0 ][1 ] == "counter@none"
954
982
955
983
984
+ @minimum_python_37_with_gevent
956
985
@pytest .mark .forked
957
986
def test_flush_recursion_protection_background_flush (
958
987
sentry_init , capture_envelopes , monkeypatch , maybe_monkeypatched_threading
959
988
):
960
- monkeypatch .setattr (metrics .MetricsAggregator , "FLUSHER_SLEEP_TIME" , 0.1 )
989
+ monkeypatch .setattr (metrics .MetricsAggregator , "FLUSHER_SLEEP_TIME" , 0.01 )
961
990
sentry_init (
962
991
release = "fun-release" ,
963
992
environment = "not-fun-env" ,
@@ -984,3 +1013,29 @@ def bad_capture_envelope(*args, **kwargs):
984
1013
m = parse_metrics (envelope .items [0 ].payload .get_bytes ())
985
1014
assert len (m ) == 1
986
1015
assert m [0 ][1 ] == "counter@none"
1016
+
1017
+
1018
+ @pytest .mark .skipif (
1019
+ not gevent or sys .version_info >= (3 , 7 ),
1020
+ reason = "Python 3.6 or lower and gevent required" ,
1021
+ )
1022
+ @pytest .mark .forked
1023
+ def test_disable_metrics_for_old_python_with_gevent (
1024
+ sentry_init , capture_envelopes , maybe_monkeypatched_threading
1025
+ ):
1026
+ if maybe_monkeypatched_threading != "greenlet" :
1027
+ pytest .skip ("Test specifically for gevent/greenlet" )
1028
+
1029
+ sentry_init (
1030
+ release = "fun-release" ,
1031
+ environment = "not-fun-env" ,
1032
+ _experiments = {"enable_metrics" : True },
1033
+ )
1034
+ envelopes = capture_envelopes ()
1035
+
1036
+ metrics .incr ("counter" )
1037
+
1038
+ Hub .current .flush ()
1039
+
1040
+ assert Hub .current .client .metrics_aggregator is None
1041
+ assert not envelopes
0 commit comments