test: remove scheduler race from snapshot freshness check
This commit is contained in:
parent
0c71dea00c
commit
5cda95eeb2
|
|
@ -325,11 +325,13 @@ async def test_live_snapshot_keeps_fresh_activity_when_work_fails(monkeypatch):
|
||||||
@pytest.mark.anyio
|
@pytest.mark.anyio
|
||||||
async def test_live_snapshot_reuses_completed_snapshot_inside_freshness_window(monkeypatch):
|
async def test_live_snapshot_reuses_completed_snapshot_inside_freshness_window(monkeypatch):
|
||||||
user_calls = 0
|
user_calls = 0
|
||||||
|
user_started = asyncio.Event()
|
||||||
release = asyncio.Event()
|
release = asyncio.Event()
|
||||||
|
|
||||||
async def user():
|
async def user():
|
||||||
nonlocal user_calls
|
nonlocal user_calls
|
||||||
user_calls += 1
|
user_calls += 1
|
||||||
|
user_started.set()
|
||||||
return {"id": 1, "login": "timmy"}
|
return {"id": 1, "login": "timmy"}
|
||||||
|
|
||||||
async def blocked_repos():
|
async def blocked_repos():
|
||||||
|
|
@ -350,13 +352,8 @@ async def test_live_snapshot_reuses_completed_snapshot_inside_freshness_window(m
|
||||||
monkeypatch.setattr(main, "notifications", empty)
|
monkeypatch.setattr(main, "notifications", empty)
|
||||||
|
|
||||||
first = asyncio.create_task(main.live_snapshot())
|
first = asyncio.create_task(main.live_snapshot())
|
||||||
await asyncio.sleep(0)
|
await user_started.wait()
|
||||||
second = asyncio.create_task(main.live_snapshot())
|
second = asyncio.create_task(main.live_snapshot())
|
||||||
for _ in range(100):
|
|
||||||
if user_calls:
|
|
||||||
break
|
|
||||||
await asyncio.to_thread(lambda: None)
|
|
||||||
assert user_calls == 1
|
|
||||||
|
|
||||||
release.set()
|
release.set()
|
||||||
await asyncio.gather(first, second)
|
await asyncio.gather(first, second)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user