Skip to content
Snippets Groups Projects
Commit 854338ca authored by Damian Johnson's avatar Damian Johnson
Browse files

Move stacktrace signaling into test invocation

Functionally teor's patch is fine as test/__init__.py is only imported
in testing contexts. That said, as a general practice it's better to
invoke functional code (like signal listeners) when a module is invoked
rather than imported.

All testing is invoked through run_tests.py's main method, so we can
register our signal handlers there instead.
parent cb774063
No related branches found
No related tags found
No related merge requests found
......@@ -7,6 +7,7 @@ Runs unit and integration tests. For usage information run this with '--help'.
"""
import os
import signal
import sys
import threading
import time
......@@ -70,6 +71,18 @@ New capabilities are:
"""
def log_traceback(sig, frame):
"""
Signal handler that logs the present traceback, and aborts our process with
exit status -1 in the case of SIGABRT.
"""
print('Signal %s received.\nTraceback:\n%s' % (sig, traceback.format_stack(frame)))
if sig == signal.SIGABRT:
sys.exit(-1)
def get_unit_tests(module_prefix = None):
"""
Provides the classes for our unit tests.
......@@ -124,6 +137,9 @@ def main():
println('%s\n' % exc)
sys.exit(1)
signal.signal(signal.SIGABRT, log_traceback)
signal.signal(signal.SIGUSR1, log_traceback)
test_config = stem.util.conf.get_config('test')
test_config.load(os.path.join(test.STEM_BASE, 'test', 'settings.cfg'))
......
......@@ -16,28 +16,10 @@ Unit and integration tests for the stem library. Helpers include...
import collections
import itertools
import os
import signal
import sys
import traceback
import stem.util.enum
import stem.version
# Install signal handlers before doing anything else
def log_traceback(sig, frame):
"""Log a stack trace. exit(-1) if the signal was SIGABRT."""
message = "Signal {} received.\nTraceback:\n".format(sig)
message += ''.join(traceback.format_stack(frame))
print(message)
if sig == signal.SIGABRT:
sys.exit(-1)
# Register handlers
# Log stack trace and exit
signal.signal(signal.SIGABRT, log_traceback)
# Log stack trace and continue
signal.signal(signal.SIGUSR1, log_traceback)
__all__ = [
'network',
'output',
......
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