Skip to content

Commit a0b8216

Browse files
committed
Change timeout test pattern
1 parent 2744cc5 commit a0b8216

2 files changed

Lines changed: 64 additions & 11 deletions

File tree

src/py/tests/test_kaleido.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -435,19 +435,31 @@ async def test_unreasonable_timeout(simple_figure_with_bytes, tmp_path):
435435
fig = simple_figure_with_bytes["fig"]
436436
opts = simple_figure_with_bytes["opts"]
437437

438-
async def slow_fig_generator() -> AsyncGenerator[FigureDict, None]:
439-
"""Generator that sleeps to simulate slow figure generation."""
440-
await asyncio.sleep(10) # This will cause timeout with small timeout value
438+
async def fig_generator() -> AsyncGenerator[FigureDict, None]:
441439
yield {
442440
"fig": fig,
443441
"path": tmp_path / "test_timeout.png",
444442
"opts": opts,
445443
}
446444

447-
# Use a small timeout that will trigger before the sleep completes
448-
async with Kaleido(timeout=1) as k:
449-
with pytest.raises((asyncio.TimeoutError, TimeoutError)):
450-
await k.write_fig(slow_fig_generator())
445+
async with Kaleido(timeout=0.1) as k:
446+
447+
async def slow_calc_fig(*_args, **_kwargs):
448+
"""Wrapper that adds sleep then fails."""
449+
await asyncio.sleep(1)
450+
pytest.fail("Should have timed out before reaching here!")
451+
452+
for _ in range(k.tabs_ready.qsize()):
453+
t = await k.tabs_ready.get()
454+
t._calc_fig = slow_calc_fig # noqa: SLF001
455+
await k.tabs_ready.put(t)
456+
457+
with pytest.raises((asyncio.TimeoutError, TimeoutError)): # noqa: PT012
458+
await k.write_fig_from_object(fig_generator(), cancel_on_error=True)
459+
pytest.fail("Should never reach this, should have raised.")
460+
461+
ret = await k.write_fig_from_object(fig_generator(), cancel_on_error=False)
462+
assert isinstance(ret[0], (asyncio.TimeoutError, TimeoutError))
451463

452464

453465
@pytest.mark.parametrize(

src/py/uv.lock

Lines changed: 45 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)