Skip to content

Commit

Permalink
fixed bad logic introducted to test_observe (#692)
Browse files Browse the repository at this point in the history
* fixed bad logic introducted to `test_observe`

`test_observe_value_times_out_with_busy_sleep` should be using a
blocking thread sleep instead of an async one.

* Fix test_observe_value_times_out_with_busy_sleep on py3.12

---------

Co-authored-by: Tom Cobb <[email protected]>
  • Loading branch information
evalott100 and coretl authored Dec 5, 2024
1 parent 4ee4eb1 commit 55eb812
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions tests/core/test_observe.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,22 @@ 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.
time.sleep(0.15)
recv.append(val)

t = asyncio.create_task(tick())
# Let it get started so we get our first update
# This is needed to fix for python 3.12, otherwise the task
# gets starved by the busy sleep
await asyncio.sleep(0.05)
start = time.time()
try:
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.3, abs=0.05)
finally:
t.cancel()

Expand Down

0 comments on commit 55eb812

Please sign in to comment.