Skip to content

Commit

Permalink
wip: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pedro-psb committed Feb 14, 2025
1 parent 1b427eb commit 0ecc3a7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
3 changes: 3 additions & 0 deletions pulpcore/tasking/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,9 @@ def dispatch(
stack.enter_context(task)
else:
notify_workers = True
_logger.info("asdfasdf*")
_logger.info("asdfasdf")
_logger.info("*" * 50)
if immediate:
prior_tasks = Task.objects.filter(
state__in=TASK_INCOMPLETE_STATES, pulp_created__lt=task.pulp_created
Expand Down
32 changes: 17 additions & 15 deletions pulpcore/tests/functional/api/test_tasking.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,61 +508,63 @@ def test_immediate_task_requires_resource(pulpcore_bindings, dispatch_task, moni
THEN an error is raised
3
WHEN dispatching a task as immediate
AND it takes longer than timeout
THEN an error is raised
"""
LT_TIMEOUT = IMMEDIATE_TIMEOUT / 2
GT_TIMEOUT = IMMEDIATE_TIMEOUT + 1
LONG_RUNNING = 5
COMMON_RESOURCE = "XYZ"

def wait_until(state, task_href, timeout=10):
for i in range(timeout):
task = pulpcore_bindings.TasksApi.read(task_href)
if task.state != state:
break
time.sleep(1)
raise RuntimeError("Timeout waiting for task to transition")

def dispatch_long_task(requires_resource):
task_href = dispatch_task(
"pulpcore.app.tasks.test.sleep",
args=(LONG_RUNNING,),
exclusive_resources=[requires_resource],
)
wait_until("running", task_href)

# Case 1
long_href = dispatch_task(
"pulpcore.app.tasks.test.sleep", args=(LONG_RUNNING,), exclusive_resources=["XYZ"]
)
wait_until("running", long_href)
dispatch_long_task(requires_resource=COMMON_RESOURCE)
task_href = dispatch_task(
"pulpcore.app.tasks.test.asleep",
args=(LT_TIMEOUT,),
immediate=True,
exclusive_resources=["XYZ"],
exclusive_resources=[COMMON_RESOURCE],
)
task = monitor_task(task_href)
assert task.state == "completed"
assert task.worker is not None

# Case 2
long_href = dispatch_task(
"pulpcore.app.tasks.test.sleep", args=(LONG_RUNNING,), exclusive_resources=["XYZ"]
)
wait_until("running", long_href)
dispatch_long_task(requires_resource=COMMON_RESOURCE)
with pytest.raises(PulpTaskError):
task_href = dispatch_task(
"pulpcore.app.tasks.test.asleep",
args=(0,),
immediate=True,
deferred=False,
exclusive_resources=["XYZ"],
exclusive_resources=[COMMON_RESOURCE],
)
monitor_task(task_href)

# Case 3
long_href = dispatch_task(
"pulpcore.app.tasks.test.sleep", args=(LONG_RUNNING,), exclusive_resources=["XYZ"]
)
wait_until("running", long_href)
dispatch_long_task(requires_resource=COMMON_RESOURCE)
with pytest.raises(PulpTaskError) as ctx:
task_href = dispatch_task(
"pulpcore.app.tasks.test.asleep",
args=(GT_TIMEOUT,),
immediate=True,
exclusive_resources=["XYZ"],
exclusive_resources=[COMMON_RESOURCE],
)
monitor_task(task_href)
assert "task timed out after" in ctx.value.task.error["description"]

0 comments on commit 0ecc3a7

Please sign in to comment.