@@ -30,15 +30,13 @@ def tearDown(self):
30
30
self ._thread .join ()
31
31
32
32
def get_metrics (self ):
33
- CeleryInstrumentor ().instrument ()
34
33
result = task_add .delay (1 , 2 )
35
34
36
35
timeout = time .time () + 60 * 1 # 1 minutes from now
37
36
while not result .ready ():
38
37
if time .time () > timeout :
39
38
break
40
39
time .sleep (0.05 )
41
- CeleryInstrumentor ().uninstrument ()
42
40
resource_metrics = (
43
41
self .memory_metrics_reader .get_metrics_data ().resource_metrics
44
42
)
@@ -88,10 +86,12 @@ def assert_metric_expected(
88
86
)
89
87
90
88
def test_basic_metric (self ):
89
+ CeleryInstrumentor ().instrument ()
91
90
start_time = default_timer ()
92
91
task_runtime_estimated = (default_timer () - start_time ) * 1000
93
92
94
93
metrics = self .get_metrics ()
94
+ CeleryInstrumentor ().uninstrument ()
95
95
self .assertEqual (len (metrics ), 1 )
96
96
97
97
task_runtime = metrics [0 ]
@@ -106,3 +106,16 @@ def test_basic_metric(self):
106
106
},
107
107
est_delta = 200 ,
108
108
)
109
+
110
+ def test_metric_uninstrument (self ):
111
+ CeleryInstrumentor ().instrument ()
112
+ metrics = self .get_metrics ()
113
+ self .assertEqual (len (metrics ), 1 )
114
+ CeleryInstrumentor ().uninstrument ()
115
+
116
+ metrics = self .get_metrics ()
117
+ self .assertEqual (len (metrics ), 1 )
118
+
119
+ for metric in metrics :
120
+ for point in list (metric .data .data_points ):
121
+ self .assertEqual (point .count , 1 )
0 commit comments