Skip to content

Commit

Permalink
Add test that confirms that the task is cancelled immedeately
Browse files Browse the repository at this point in the history
  • Loading branch information
davidkleiven committed Feb 9, 2024
1 parent 8ae6bb6 commit da89e44
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions tests/test_async_sparql_wrapper.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down Expand Up @@ -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

0 comments on commit da89e44

Please sign in to comment.