Exemple #1
0
 def test_get_call_context(self):
     # it should return a context even if not attached to the Task
     ctx = self.tracer.get_call_context()
     assert ctx is not None
     # test that it behaves the wrong way
     task = asyncio_current_task()
     assert task
     task_ctx = getattr(task, "__datadog_context", None)
     assert task_ctx is None
async def test_get_call_context(tracer):
    tracer.configure(context_provider=DefaultContextProvider())
    ctx = tracer.current_trace_context()
    assert ctx is None
    # test that it behaves the wrong way
    task = asyncio_current_task()
    assert task
    task_ctx = getattr(task, "__datadog_context", None)
    assert task_ctx is None
 def test_context_task_none(self):
     # it should handle the case where a Task is not available
     # Note: the @mark_asyncio is missing to simulate an execution
     # without a Task
     task = asyncio_current_task()
     # the task is not available
     assert task is None
     # but a new Context is still created making the operation safe
     ctx = self.tracer.get_call_context()
     assert ctx is not None
Exemple #4
0
async def test_get_call_context(tracer):
    tracer.configure(context_provider=DefaultContextProvider())
    # it should return a context even if not attached to the Task
    ctx = tracer.get_call_context()
    assert ctx is not None
    # test that it behaves the wrong way
    task = asyncio_current_task()
    assert task
    task_ctx = getattr(task, "__datadog_context", None)
    assert task_ctx is None
 def test_get_call_context(self):
     # it should return the context attached to the current Task
     # or create a new one
     task = asyncio_current_task()
     ctx = getattr(task, "__datadog_context", None)
     assert ctx is None
     # get the context from the loop creates a new one that
     # is attached to the Task object
     ctx = self.tracer.get_call_context()
     assert ctx == getattr(task, "__datadog_context", None)
Exemple #6
0
def test_context_task_none(tracer):
    loop = asyncio.new_event_loop()
    asyncio.set_event_loop(loop)
    # it should handle the case where a Task is not available
    # Note: the @pytest.mark.asyncio is missing to simulate an execution
    # without a Task
    task = asyncio_current_task()
    # the task is not available
    assert task is None

    ctx = tracer.current_trace_context()
    assert ctx is None