Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure that assertion failures in threads trigger test failures #86

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 20 additions & 9 deletions beeline/test_beeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,23 @@ def my_sum(a, b):
# check that an event was sent, from which we can infer that the function was wrapped
self.assertTrue(_beeline.tracer_impl._run_hooks_and_send.called)

@staticmethod
def raising_run_in_thread(target):
closure_dict = {}

def wrapper():
try:
target()
except Exception as exc:
closure_dict["thread_exception"] = exc

thread = threading.Thread(target=wrapper)
thread.start()
thread.join()

if "thread_exception" in closure_dict:
raise closure_dict["thread_exception"]

def test_treaded_trace(self):
_beeline = beeline.Beeline()

Expand All @@ -164,9 +181,7 @@ def thread_func():
# confirm no trace state in new thread
self.assertFalse(hasattr(_beeline.tracer_impl._state, 'trace_id'))

t = threading.Thread(target=thread_func)
t.start()
t.join()
self.raising_run_in_thread(target=thread_func)

@beeline.traced_thread
def traced_thread_func():
Expand All @@ -176,9 +191,7 @@ def traced_thread_func():
self.assertEqual(span.trace_id, "asdf")
self.assertEqual(span.parent_id, _beeline.tracer_impl._state.stack[0].id)

t = threading.Thread(target=traced_thread_func)
t.start()
t.join()
self.raising_run_in_thread(target=traced_thread_func)

# test use of beeline client
@_beeline.traced_thread
Expand All @@ -189,9 +202,7 @@ def traced_thread_func_2():
self.assertEqual(span.trace_id, "asdf")
self.assertEqual(span.parent_id, _beeline.tracer_impl._state.stack[0].id)

t = threading.Thread(target=traced_thread_func_2)
t.start()
t.join()
self.raising_run_in_thread(target=traced_thread_func_2)

def test_finish_span_none(self):
''' ensure finish_span does not crash if an empty span is passed to it '''
Expand Down