Skip to content

Commit 31f68c2

Browse files
committed
fix bug
1 parent ee6c0e2 commit 31f68c2

File tree

4 files changed

+39
-9
lines changed

4 files changed

+39
-9
lines changed

poetry.lock

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ dependencies = [
1919
"requests",
2020
"simplejson (>=3,<4)",
2121
]
22-
optional-dependencies = { test-tools = ["pyfakefs (>=5,<6)"] }
22+
optional-dependencies = { test-tools = [
23+
"pyfakefs (>=5,<6)",
24+
"pytest-django (>=4,<5)",
25+
] }
2326
authors = [
2427
{ name = "Matthew Elwell" },
2528
{ name = "Gagan Trivedi" },

src/common/test_tools/plugin.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
Snapshot,
1414
SnapshotFixture,
1515
)
16+
from task_processor.task_run_method import TaskRunMethod
1617

1718

1819
def pytest_addoption(parser: pytest.Parser) -> None:
@@ -104,7 +105,7 @@ def run_tasks_impl(
104105
db: None,
105106
task_processor_mode: None,
106107
) -> RunTasksFixture:
107-
settings.TASK_RUN_METHOD = "TASK_PROCESSOR"
108+
settings.TASK_RUN_METHOD = TaskRunMethod.TASK_PROCESSOR
108109

109110
from task_processor.processor import run_tasks
110111

tests/unit/common/test_tools/test_plugin.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
from datetime import datetime, timedelta
2+
13
import prometheus_client
24
import pytest
35

46
from common.test_tools import AssertMetricFixture, RunTasksFixture
57
from common.test_tools.plugin import assert_metric_impl
68
from common.test_tools.utils import edition_printer
79
from task_processor.decorators import register_task_handler
10+
from task_processor.models import Task
811

912

1013
def test_assert_metrics__asserts_expected(
@@ -75,3 +78,26 @@ def my_task() -> None:
7578
assert len(task_runs) == 1
7679
assert task_runs[0].task.task_identifier == "test_plugin.my_task"
7780
assert task_runs[0].result == "SUCCESS"
81+
82+
83+
def test_run_tasks__delay_inside_task__runs_expected(
84+
run_tasks: RunTasksFixture,
85+
) -> None:
86+
# Given
87+
@register_task_handler()
88+
def my_task() -> None:
89+
return None
90+
91+
@register_task_handler()
92+
def calling_task() -> None:
93+
my_task.delay(delay_until=datetime.now() + timedelta(hours=1))
94+
95+
calling_task.delay()
96+
97+
# When
98+
task_runs = run_tasks(num_tasks=1)
99+
100+
# Then
101+
assert len(task_runs) == 1
102+
assert Task.objects.count() == 2
103+
assert Task.objects.latest("scheduled_for").task_identifier == "test_plugin.my_task"

0 commit comments

Comments
 (0)