Skip to content

Commit 0ecc3a7

Browse files
committed
wip: fix tests
1 parent 1b427eb commit 0ecc3a7

2 files changed

Lines changed: 20 additions & 15 deletions

File tree

pulpcore/tasking/tasks.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,9 @@ def dispatch(
225225
stack.enter_context(task)
226226
else:
227227
notify_workers = True
228+
_logger.info("asdfasdf*")
229+
_logger.info("asdfasdf")
230+
_logger.info("*" * 50)
228231
if immediate:
229232
prior_tasks = Task.objects.filter(
230233
state__in=TASK_INCOMPLETE_STATES, pulp_created__lt=task.pulp_created

pulpcore/tests/functional/api/test_tasking.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -508,61 +508,63 @@ def test_immediate_task_requires_resource(pulpcore_bindings, dispatch_task, moni
508508
THEN an error is raised
509509
510510
3
511+
WHEN dispatching a task as immediate
511512
AND it takes longer than timeout
512513
THEN an error is raised
513514
"""
514515
LT_TIMEOUT = IMMEDIATE_TIMEOUT / 2
515516
GT_TIMEOUT = IMMEDIATE_TIMEOUT + 1
516517
LONG_RUNNING = 5
518+
COMMON_RESOURCE = "XYZ"
517519

518520
def wait_until(state, task_href, timeout=10):
519521
for i in range(timeout):
520522
task = pulpcore_bindings.TasksApi.read(task_href)
521523
if task.state != state:
522524
break
523525
time.sleep(1)
526+
raise RuntimeError("Timeout waiting for task to transition")
527+
528+
def dispatch_long_task(requires_resource):
529+
task_href = dispatch_task(
530+
"pulpcore.app.tasks.test.sleep",
531+
args=(LONG_RUNNING,),
532+
exclusive_resources=[requires_resource],
533+
)
534+
wait_until("running", task_href)
524535

525536
# Case 1
526-
long_href = dispatch_task(
527-
"pulpcore.app.tasks.test.sleep", args=(LONG_RUNNING,), exclusive_resources=["XYZ"]
528-
)
529-
wait_until("running", long_href)
537+
dispatch_long_task(requires_resource=COMMON_RESOURCE)
530538
task_href = dispatch_task(
531539
"pulpcore.app.tasks.test.asleep",
532540
args=(LT_TIMEOUT,),
533541
immediate=True,
534-
exclusive_resources=["XYZ"],
542+
exclusive_resources=[COMMON_RESOURCE],
535543
)
536544
task = monitor_task(task_href)
537545
assert task.state == "completed"
538546
assert task.worker is not None
539547

540548
# Case 2
541-
long_href = dispatch_task(
542-
"pulpcore.app.tasks.test.sleep", args=(LONG_RUNNING,), exclusive_resources=["XYZ"]
543-
)
544-
wait_until("running", long_href)
549+
dispatch_long_task(requires_resource=COMMON_RESOURCE)
545550
with pytest.raises(PulpTaskError):
546551
task_href = dispatch_task(
547552
"pulpcore.app.tasks.test.asleep",
548553
args=(0,),
549554
immediate=True,
550555
deferred=False,
551-
exclusive_resources=["XYZ"],
556+
exclusive_resources=[COMMON_RESOURCE],
552557
)
553558
monitor_task(task_href)
554559

555560
# Case 3
556-
long_href = dispatch_task(
557-
"pulpcore.app.tasks.test.sleep", args=(LONG_RUNNING,), exclusive_resources=["XYZ"]
558-
)
559-
wait_until("running", long_href)
561+
dispatch_long_task(requires_resource=COMMON_RESOURCE)
560562
with pytest.raises(PulpTaskError) as ctx:
561563
task_href = dispatch_task(
562564
"pulpcore.app.tasks.test.asleep",
563565
args=(GT_TIMEOUT,),
564566
immediate=True,
565-
exclusive_resources=["XYZ"],
567+
exclusive_resources=[COMMON_RESOURCE],
566568
)
567569
monitor_task(task_href)
568570
assert "task timed out after" in ctx.value.task.error["description"]

0 commit comments

Comments
 (0)