Skip to content

Commit

Permalink
fixed bad logic introducted to test_observe
Browse files Browse the repository at this point in the history
`test_observe_value_times_out_with_busy_sleep` should be using a
blocking thread sleep instead of an async one.
  • Loading branch information
evalott100 committed Dec 5, 2024
1 parent 4ee4eb1 commit ba31b91
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions tests/core/test_observe.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ async def tick():

async def watch():
async for val in observe_value(sig, done_timeout=0.2):
await asyncio.sleep(0.1)
# This is a test to prove a subtle timing bug where the inner loop
# of observe_value was blocking the event loop.
# This gives enough time for two ticks, but no more.
time.sleep(0.09)
recv.append(val)

t = asyncio.create_task(tick())
Expand All @@ -95,7 +98,7 @@ async def watch():
with pytest.raises(asyncio.TimeoutError):
await watch()
assert recv == [0, 1]
assert time.time() - start == pytest.approx(0.2, abs=0.05)
assert time.time() - start == pytest.approx(0.25, abs=0.05)
finally:
t.cancel()

Expand Down

0 comments on commit ba31b91

Please sign in to comment.