Skip to content

Commit

Permalink
test: add terminator tests
Browse files Browse the repository at this point in the history
  • Loading branch information
phi-friday committed Feb 29, 2024
1 parent a06a06c commit 8b5b939
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion tests/test_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,18 @@ def temp_func(x: int) -> None:
assert isinstance(result, AsyncResult)
pytest.raises(RuntimeError, result.result)

def test_terminator(self):
executor = TimeoutExecutor(0.5)

def temp_func() -> None:
time.sleep(1)

result = executor.apply(temp_func)
assert isinstance(result, AsyncResult)
pytest.raises(TimeoutError, result.result)

assert result._terminator.is_active is True # noqa: SLF001


@pytest.mark.anyio()
class TestExecutorAsync:
Expand Down Expand Up @@ -129,7 +141,24 @@ async def lambdalike() -> int:
except Exception as exc: # noqa: BLE001
assert isinstance(exc, TimeoutError) # noqa: PT017
else:
raise Exception("PicklingError does not occur") # noqa: TRY002
raise Exception("TimeoutError does not occur") # noqa: TRY002

async def test_terminator(self):
executor = TimeoutExecutor(0.5)

async def temp_func() -> None:
await anyio.sleep(1)

result = await executor.delay(temp_func)
assert isinstance(result, AsyncResult)
try:
await result.delay()
except Exception as exc: # noqa: BLE001
assert isinstance(exc, TimeoutError) # noqa: PT017
else:
raise Exception("TimeoutError does not occur") # noqa: TRY002

assert result._terminator.is_active is True # noqa: SLF001


def sample_func(*args: Any, **kwargs: Any) -> tuple[tuple[Any, ...], dict[str, Any]]:
Expand Down

0 comments on commit 8b5b939

Please sign in to comment.