Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Timeout with an async iteration #832

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions python/pytests/execution_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import kaskada as kd
import pandas as pd
import pytest
import asyncio


@pytest.fixture
Expand Down Expand Up @@ -139,3 +140,33 @@ async def test_history(golden, source_int64) -> None:
)
)
)

async def test_iter_pandas_async_live_timeout(golden, source_int64) -> None:
data2 = "\n".join(
[
"time,key,m,n",
"1996-12-20T16:39:57,A,5,10",
"1996-12-20T16:39:58,B,24,3",
"1996-12-20T16:39:59,A,17,6",
"1996-12-20T16:40:00,C,,9",
"1996-12-20T16:40:01,A,12,",
"1996-12-20T16:40:02,A,,",
]
)

execution = source_int64.run_iter(mode="live")

# Await the first batch.
golden.jsonl(await execution.__anext__())

# Add data and await the second batch.
await source_int64.add_string(data2)
golden.jsonl(await execution.__anext__())

with pytest.raises(TimeoutError):
async with asyncio.timeout(1):
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if we want to check this in without marking it as a slow test. Specifically, it will wait at least 1 second for the timeout to occur. This can be increased further (10s) to verify that it isn't just "getting lucky" in terms of hitting an empty batch or somethnig like that.

await execution.__anext__()

execution.stop()
with pytest.raises(StopAsyncIteration):
print(await execution.__anext__())
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{"_time":"1996-12-19T16:39:57.000000000","_key":"A","time":"1996-12-19T16:39:57.000000000","key":"A","m":5.0,"n":10.0}
{"_time":"1996-12-19T16:39:58.000000000","_key":"B","time":"1996-12-19T16:39:58.000000000","key":"B","m":24.0,"n":3.0}
{"_time":"1996-12-19T16:39:59.000000000","_key":"A","time":"1996-12-19T16:39:59.000000000","key":"A","m":17.0,"n":6.0}
{"_time":"1996-12-19T16:40:00.000000000","_key":"A","time":"1996-12-19T16:40:00.000000000","key":"A","m":null,"n":9.0}
{"_time":"1996-12-19T16:40:01.000000000","_key":"A","time":"1996-12-19T16:40:01.000000000","key":"A","m":12.0,"n":null}
{"_time":"1996-12-19T16:40:02.000000000","_key":"A","time":"1996-12-19T16:40:02.000000000","key":"A","m":null,"n":null}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{"_time":"1996-12-20T16:39:57.000000000","_key":"A","time":"1996-12-20T16:39:57.000000000","key":"A","m":5.0,"n":10.0}
{"_time":"1996-12-20T16:39:58.000000000","_key":"B","time":"1996-12-20T16:39:58.000000000","key":"B","m":24.0,"n":3.0}
{"_time":"1996-12-20T16:39:59.000000000","_key":"A","time":"1996-12-20T16:39:59.000000000","key":"A","m":17.0,"n":6.0}
{"_time":"1996-12-20T16:40:00.000000000","_key":"C","time":"1996-12-20T16:40:00.000000000","key":"C","m":null,"n":9.0}
{"_time":"1996-12-20T16:40:01.000000000","_key":"A","time":"1996-12-20T16:40:01.000000000","key":"A","m":12.0,"n":null}
{"_time":"1996-12-20T16:40:02.000000000","_key":"A","time":"1996-12-20T16:40:02.000000000","key":"A","m":null,"n":null}