Skip to content

Commit

Permalink
test/threads: fix state leakage across tests
Browse files Browse the repository at this point in the history
test_threaded_bad_options was only passing in CI because it was running
after test_threaded_invalid_binary, which altered the base class to
ignore some exceptions.

Restructure the tests by using the fact that ThreadedAustin.join will
bubble up any exception that happened during startup. This avoids
manipulating global state in test_threaded_invalid_binary.

Fixes P403n1x87#13.
  • Loading branch information
delroth committed Oct 31, 2022
1 parent 4292f1c commit b1bbc43
Showing 1 changed file with 6 additions and 19 deletions.
25 changes: 6 additions & 19 deletions test/test_threads.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,9 @@

from austin import AustinError
from austin import AustinTerminated
from austin.simple import SimpleAustin
from austin.threads import ThreadedAustin


def check_raises(exc):
def _check_raises_decorator(f):
def _check_raises_wrapper(*args, **kwargs):
with raises(exc):
f(*args, **kwargs)

return _check_raises_wrapper

return _check_raises_decorator


class TestThreadedAustin(ThreadedAustin):
__test__ = False

Expand Down Expand Up @@ -72,10 +60,6 @@ def assert_callbacks_called(self):
class InvalidBinaryThreadedAustin(ThreadedAustin):
BINARY = "_austin"

@check_raises(AustinError)
def run(self, *args, **kwargs):
super().run(*args, **kwargs)


def test_threaded():
austin = TestThreadedAustin()
Expand Down Expand Up @@ -109,8 +93,10 @@ def terminate_callback(*args):


def test_threaded_invalid_binary():
SimpleAustin.start = check_raises(AustinError)(SimpleAustin.start)
InvalidBinaryThreadedAustin(sample_callback=lambda x: None).start(["python"])
austin = InvalidBinaryThreadedAustin(sample_callback=lambda x: None)
austin.start(["python"])
with raises(AustinError):
austin.join()


def test_threaded_no_sample_callback():
Expand All @@ -121,4 +107,5 @@ def test_threaded_no_sample_callback():
def test_threaded_bad_options():
austin = TestThreadedAustin(terminate_callback=lambda *args: None)
austin.start(["-I", "1000", "python", "-c", "for i in range(1000000): print(i)"])
austin.join()
with raises(AustinError):
austin.join()

0 comments on commit b1bbc43

Please sign in to comment.