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

Add test that confirms that the task is cancelled immedeately #223

Merged
merged 1 commit into from
Feb 9, 2024
Merged
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
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
Loading