This repository was archived by the owner on Sep 17, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 247
Expand file tree
/
Copy pathtest_noop_tracer.py
More file actions
50 lines (39 loc) · 2 KB
/
test_noop_tracer.py
File metadata and controls
50 lines (39 loc) · 2 KB
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
import unittest
from unittest.mock import patch, MagicMock
from opencensus.trace.tracers.noop_tracer import NoopTracer
from opencensus.ext.threading.trace import wrap_submit, wrap_apply_async
class TestNoopTracer(unittest.TestCase):
"""
In case no OpenCensus context is present (i.e. we have a NoopTracer), do _not_ pass down tracer in apply_async
and submit; instead invoke function directly.
"""
@patch("opencensus.ext.threading.trace.wrap_task_func")
@patch("opencensus.trace.execution_context.get_opencensus_tracer")
def test_noop_tracer_apply_async(
self, get_opencensus_tracer_mock: MagicMock, wrap_task_func_mock: MagicMock
):
mock_tracer = NoopTracer()
get_opencensus_tracer_mock.return_value = mock_tracer
submission_function_mock = MagicMock()
original_function_mock = MagicMock()
wrap_apply_async(submission_function_mock)(None, original_function_mock)
# check whether invocation of original function _has_ happened
submission_function_mock.assert_called_once_with(
None, original_function_mock, args=(), kwds={}
)
# ensure that the function has _not_ been wrapped
wrap_task_func_mock.assert_not_called()
@patch("opencensus.ext.threading.trace.wrap_task_func")
@patch("opencensus.trace.execution_context.get_opencensus_tracer")
def test_noop_tracer_wrap_submit(
self, get_opencensus_tracer_mock: MagicMock, wrap_task_func_mock: MagicMock
):
mock_tracer = NoopTracer()
get_opencensus_tracer_mock.return_value = mock_tracer
submission_function_mock = MagicMock()
original_function_mock = MagicMock()
wrap_submit(submission_function_mock)(None, original_function_mock)
# check whether invocation of original function _has_ happened
submission_function_mock.assert_called_once_with(None, original_function_mock)
# ensure that the function has _not_ been wrapped
wrap_task_func_mock.assert_not_called()