diff --git a/tests/test_async_sparql_wrapper.py b/tests/test_async_sparql_wrapper.py index eabc07ae..8c0b07c2 100644 --- a/tests/test_async_sparql_wrapper.py +++ b/tests/test_async_sparql_wrapper.py @@ -1,9 +1,11 @@ +import asyncio import os from string import Template import pytest import t_utils.common as t_common +from cimsparql.async_sparql_wrapper import retry_task from cimsparql.graphdb import make_async @@ -31,3 +33,15 @@ async def test_async_rdf4j_picasso_data(query: str, expect: list[dict[str, str]] client = make_async(client) result = await client.exec_query(f"{prefixes}\n{query}") assert result == expect + + +@pytest.mark.asyncio +async def test_return_immediately_on_cancel(): + async def task() -> None: + await asyncio.sleep(10.0) + raise RuntimeError("This task always fails") + + retry_10_times_task = asyncio.create_task(retry_task(lambda: task(), 10, 2)) + retry_10_times_task.cancel() + with pytest.raises(asyncio.CancelledError): + await retry_10_times_task