Skip to content

Commit

Permalink
Updated test workflow. (#392)
Browse files Browse the repository at this point in the history
* Updated test workflow and tests
  • Loading branch information
s3rius authored Dec 18, 2024
1 parent ae6b214 commit ff6dc26
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 63 deletions.
15 changes: 4 additions & 11 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ name: Testing taskiq
on:
pull_request:
push:
branches:
- develop
- master

jobs:
lint:
Expand All @@ -30,15 +27,11 @@ jobs:
- name: Run lint check
run: poetry run pre-commit run -a ${{ matrix.cmd }}
pytest:
permissions:
checks: write
pull-requests: write
contents: write
strategy:
matrix:
py_version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
py_version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
pydantic_ver: ["<2", ">=2.5,<3"]
os: [ubuntu-latest, windows-latest]
os: [ubuntu-latest, windows-latest, macos-latest]
runs-on: "${{ matrix.os }}"
steps:
- uses: actions/checkout@v2
Expand All @@ -58,9 +51,9 @@ jobs:
- name: Generate report
run: poetry run coverage xml
- name: Upload coverage reports to Codecov with GitHub Action
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v5
if: matrix.os == 'ubuntu-latest' && matrix.py_version == '3.9'
with:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: false
token: ${{ secrets.CODECOV_TOKEN }}
verbose: true
73 changes: 40 additions & 33 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 24 additions & 19 deletions tests/middlewares/test_task_retry.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import asyncio
import time

import pytest

Expand All @@ -16,18 +15,18 @@ async def test_wait_result() -> None:
runs = 0

@broker.task(retry_on_error=True)
def run_task() -> str:
async def run_task() -> str:
nonlocal runs

if runs == 0:
runs += 1
raise Exception("Retry")

time.sleep(0.2)
return "hello world!"

task = await run_task.kiq()
resp = await task.wait_result(0.1, timeout=1)
assert runs == 1

assert resp.return_value == "hello world!"

Expand All @@ -39,24 +38,28 @@ async def test_wait_result_error() -> None:
SimpleRetryMiddleware(no_result_on_retry=False),
)
runs = 0
lock = asyncio.Lock()

@broker.task(retry_on_error=True)
def run_task() -> str:
nonlocal runs
async def run_task() -> str:
nonlocal runs, lock

await lock.acquire()

if runs == 0:
runs += 1
raise ValueError("Retry")

time.sleep(0.2)
return "hello world!"

task = await run_task.kiq()
resp = await task.wait_result(0.1, timeout=1)
with pytest.raises(ValueError):
resp.raise_for_error()
assert resp.is_err
assert runs == 1

broker.result_backend.results.pop(task.task_id) # type: ignore
lock.release()

await asyncio.sleep(0.2)
resp = await task.wait_result(timeout=1)
assert resp.return_value == "hello world!"

Expand All @@ -67,32 +70,34 @@ async def test_wait_result_no_result() -> None:
broker = InMemoryBroker().with_middlewares(
SimpleRetryMiddleware(no_result_on_retry=False),
)
done = False
done = asyncio.Event()
runs = 0
lock = asyncio.Lock()

@broker.task(retry_on_error=True)
def run_task() -> str:
nonlocal runs, done
async def run_task() -> str:
nonlocal runs, done, lock

await lock.acquire()

if runs == 0:
runs += 1
raise ValueError("Retry")

time.sleep(0.2)
done = True
done.set()
raise NoResultError

task = await run_task.kiq()
resp = await task.wait_result(0.1, timeout=1)
with pytest.raises(ValueError):
resp.raise_for_error()

await asyncio.sleep(0.2)
resp = await task.wait_result(timeout=1)
with pytest.raises(ValueError):
resp.raise_for_error()
broker.result_backend.results.pop(task.task_id) # type: ignore
lock.release()

assert done
assert await asyncio.wait_for(done.wait(), timeout=1)
with pytest.raises(KeyError):
await broker.result_backend.get_result(task.task_id)


@pytest.mark.anyio
Expand Down

0 comments on commit ff6dc26

Please sign in to comment.