Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dansondergaard committed Jul 31, 2023
1 parent 9509ecb commit 7ffc361
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
38 changes: 19 additions & 19 deletions tests/backends/test_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pytest
import pytest_asyncio

from gwf.backends.local import Client, Scheduler
from gwf.backends.local import Client, LocalStatus, Scheduler


@pytest_asyncio.fixture
Expand All @@ -17,34 +17,34 @@ async def s(tmp_path):
async def test_successful_task_without_deps(s):
tid = await s.enqueue_task("foo", "exit 0", ".", None, set())
await s.wait_for({tid}, timeout=1)
assert s.get_task_state(tid) == "completed"
assert s.get_task_state(tid) == LocalStatus.COMPLETED


@pytest.mark.asyncio
async def test_successful_task_with_dependent(s):
tid1 = await s.enqueue_task("foo", "exit 0", ".", None, set())
tid2 = await s.enqueue_task("foo", "exit 0", ".", None, set([tid1]))
await s.wait_for({tid1, tid2}, timeout=1)
assert s.get_task_state(tid1) == "completed"
assert s.get_task_state(tid2) == "completed"
assert s.get_task_state(tid1) == LocalStatus.COMPLETED
assert s.get_task_state(tid2) == LocalStatus.COMPLETED


@pytest.mark.asyncio
async def test_task_with_dependent_submitted_later(s):
tid1 = await s.enqueue_task("foo", "exit 0", ".", None, set())
await s.wait_for({tid1})
assert s.get_task_state(tid1) == "completed"
assert s.get_task_state(tid1) == LocalStatus.COMPLETED

tid2 = await s.enqueue_task("foo", "exit 0", ".", None, set([tid1]))
await s.wait_for({tid2})
assert s.get_task_state(tid2) == "completed"
assert s.get_task_state(tid2) == LocalStatus.COMPLETED


@pytest.mark.asyncio
async def test_failing_task_without_deps(s):
tid = await s.enqueue_task("foo", "exit 1", ".", None, set())
await s.wait_for({tid}, timeout=1)
assert s.get_task_state(tid) == "failed"
assert s.get_task_state(tid) == LocalStatus.FAILED


@pytest.mark.asyncio
Expand All @@ -55,9 +55,9 @@ async def test_failed_task_with_dependents_1(s):
await asyncio.sleep(0.1)
await s.cancel_task(tid1)
await s.wait_for({tid1, tid2, tid3})
assert s.get_task_state(tid1) == "failed"
assert s.get_task_state(tid2) == "failed"
assert s.get_task_state(tid3) == "failed"
assert s.get_task_state(tid1) == LocalStatus.FAILED
assert s.get_task_state(tid2) == LocalStatus.FAILED
assert s.get_task_state(tid3) == LocalStatus.FAILED


@pytest.mark.asyncio
Expand All @@ -68,23 +68,23 @@ async def test_failed_task_with_dependents_2(s):
await asyncio.sleep(0.1)
await s.cancel_task(tid1)
await s.wait_for({tid1, tid2, tid3})
assert s.get_task_state(tid1) == "completed"
assert s.get_task_state(tid2) == "failed"
assert s.get_task_state(tid3) == "failed"
assert s.get_task_state(tid1) == LocalStatus.COMPLETED
assert s.get_task_state(tid2) == LocalStatus.FAILED
assert s.get_task_state(tid3) == LocalStatus.FAILED


@pytest.mark.asyncio
async def test_task_without_deps_times_out(s):
tid = await s.enqueue_task("foo", "sleep 2", ".", 1, set())
await s.wait_for({tid})
assert s.get_task_state(tid) == "killed"
assert s.get_task_state(tid) == LocalStatus.KILLED


@pytest.mark.asyncio
async def test_task_without_deps_completes_within_timelimit(s):
tid = await s.enqueue_task("foo", "sleep 1", ".", 2, set())
await s.wait_for({tid})
assert s.get_task_state(tid) == "completed"
assert s.get_task_state(tid) == LocalStatus.COMPLETED


@pytest.mark.asyncio
Expand All @@ -93,7 +93,7 @@ async def test_cancelled_task_without_deps(s):
await asyncio.sleep(0.1)
await s.cancel_task(tid)
await s.wait_for({tid}, timeout=1)
assert s.get_task_state(tid) == "cancelled"
assert s.get_task_state(tid) == LocalStatus.CANCELLED


@pytest.mark.asyncio
Expand All @@ -104,9 +104,9 @@ async def test_cancelled_task_with_dependents(s):
await asyncio.sleep(0.1)
await s.cancel_task(tid1)
await s.wait_for({tid1, tid2, tid3})
assert s.get_task_state(tid1) == "cancelled"
assert s.get_task_state(tid2) == "cancelled"
assert s.get_task_state(tid3) == "cancelled"
assert s.get_task_state(tid1) == LocalStatus.CANCELLED
assert s.get_task_state(tid2) == LocalStatus.CANCELLED
assert s.get_task_state(tid3) == LocalStatus.CANCELLED


@pytest.mark.asyncio
Expand Down
2 changes: 1 addition & 1 deletion tests/plugins/test_cancel.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def test_cancel_no_targets_specified_should_ask_for_confirmation_and_cancel_all_
):
result = cli_runner.invoke(main, ["cancel"], input="y")
lines = result.output.strip().split("\n")
assert len(lines) == 4
assert len(lines) == 3
assert "Cancelling target Target1" in lines
assert "Cancelling target Target2" in lines

Expand Down

0 comments on commit 7ffc361

Please sign in to comment.