-
Notifications
You must be signed in to change notification settings - Fork 19
/
test_stopwatch_global.py
54 lines (42 loc) · 1.9 KB
/
test_stopwatch_global.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import pytest
from mock import Mock
from stopwatch_global import (
global_sw,
global_sw_del,
global_sw_init,
)
@pytest.fixture
def global_sw_fixture(request):
request.addfinalizer(global_sw_del)
@pytest.mark.usefixtures('global_sw_fixture')
class TestStopWatchGlobal(object):
def test_global_sw(self):
global_sw_init()
with global_sw().timer('root'):
pass
last_report = global_sw().get_last_aggregated_report()
assert list(last_report.aggregated_values.keys()) == ['root']
@staticmethod
def add_spans():
with global_sw().timer('parent', start_time=20, end_time=80):
global_sw().add_span_annotation('parent_annotation', 1)
with global_sw().timer('child', start_time=40, end_time=60):
global_sw().add_span_annotation('child_annotation', 1)
def test_callbacks(self):
tracing_func = Mock()
agg_timers_and_tracing_func = Mock()
global_sw_init(export_tracing_func=tracing_func,
export_aggregated_timers_and_tracing_func=agg_timers_and_tracing_func)
self.add_spans()
last_report = global_sw().get_last_aggregated_report()
reported_traces = global_sw().get_last_trace_report()
assert sorted(last_report.aggregated_values.keys()) == ['parent', 'parent#child']
assert len(reported_traces) == 2
assert reported_traces[0].trace_annotations[0].key == 'child_annotation'
assert reported_traces[1].trace_annotations[0].key == 'parent_annotation'
tracing_func.assert_called_once_with(reported_traces=reported_traces)
agg_timers_and_tracing_func.assert_called_once_with(aggregated_report=last_report,
reported_traces=reported_traces)