Skip to content

Commit

Permalink
Merge pull request ppb#215 from astronouth7303/testutil-timing-help
Browse files Browse the repository at this point in the history
Improve flakiness of Failer tests
  • Loading branch information
AstraLuma authored Mar 26, 2019
2 parents 31639c3 + 7b02ed9 commit 32d28f2
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions tests/test_testutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,28 @@ def test_quitter(loop_count):
raise AssertionError("Quitter did not raise a quit event.")


def test_failer():
def test_failer_immediate():
failer = testutil.Failer(fail=lambda e: True, message="Expected failure.")

with raises(AssertionError):
failer.activate(None)


def test_failer_timed():
failer = testutil.Failer(fail=lambda e: False, message="Should time out", run_time=0.1)
last_tick = monotonic()
run_time = 0

with raises(AssertionError) as e:
while True:
start_time = monotonic()

while True:
try:
failer.activate(None)
tick = monotonic()
run_time += tick - last_tick
last_tick = tick
if run_time >= 0.11:
except AssertionError as e:
if e.args[0] == "Test ran too long.":
end_time = monotonic()
break
assert e.value.args[0] == "Test ran too long."
else:
raise

run_time = end_time - start_time

assert abs(run_time - 0.1) <= 0.01

0 comments on commit 32d28f2

Please sign in to comment.