Skip to content
Snippets Groups Projects
Commit 03616f9f authored by Piotr Maślanka's avatar Piotr Maślanka
Browse files

more coverage

parent 086d1a66
No related branches found
No related tags found
No related merge requests found
......@@ -21,6 +21,9 @@ def call_in_separate_thread(*t_args, delay: float = 0, **t_kwargs):
The decorated routine will return a Future that is waitable to get the result
(or the exception) of the function.
The returned Future will have an extra argument, "thread" that links to the thread
instance spawned.
The arguments given here will be passed to thread's constructor, so use like:
:param delay: seconds to wait before launching function
......@@ -38,6 +41,7 @@ def call_in_separate_thread(*t_args, delay: float = 0, **t_kwargs):
def __init__(self):
self.future = Future()
super().__init__(*t_args, **t_kwargs)
self.future.thread = self
def run(self):
if not self.future.set_running_or_notify_cancel():
......
......@@ -12,7 +12,9 @@ try:
from opentracing import Span
except ImportError:
class Span:
pass
@classmethod
def _on_error(cls, span, exc_type, value, traceback):
pass
def trace_function(tracer, name: str, tags: tp.Optional[dict] = None,
......
import unittest
from satella.opentracing import trace_exception
from satella.coding.concurrent import call_in_separate_thread
from satella.opentracing import trace_exception, trace_future
from unittest import mock
class TestOpentracing(unittest.TestCase):
def test_trace_future(self):
@call_in_separate_thread()
def test_me():
pass
fut = test_me()
span = mock.Mock()
trace_future(fut, span)
fut.result()
fut.thread.join()
span.finish.assert_called()
def test_trace_exception_none(self):
trace_exception(None)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment