33import json
44import pytest
55import time
6- import logging
76
87from aiohttp import BasicAuth
98from datetime import datetime
@@ -475,23 +474,22 @@ def test_succeeds_on_api_worker(self, pulpcore_bindings, dispatch_task):
475474 def test_executes_on_api_worker_when_no_async (
476475 self ,
477476 pulpcore_bindings ,
478- dispatch_task ,
479- caplog ,
477+ dispatch_task_with_stderr ,
480478 ):
481479 """
482480 GIVEN a task with no resource requirements
483481 AND the task IS NOT an async function
484482 WHEN dispatching a task as immediate
485483 THEN the task completes with no associated worker
486484 """
487- caplog .set_level (logging .WARNING )
488485 # TODO: on 3.85 this should throw an error
489- task_href = dispatch_task (
486+ task_href , stderr = dispatch_task_with_stderr (
490487 "pulpcore.app.tasks.test.sleep" , args = (LT_TIMEOUT ,), immediate = True
491488 )
492489 task = pulpcore_bindings .TasksApi .read (task_href )
493490 assert task .state == "completed"
494491 assert task .worker is None
492+ assert "Support for non-coroutine immediate tasks will be dropped" in stderr
495493
496494 @pytest .mark .parallel
497495 def test_timeouts_on_api_worker (self , pulpcore_bindings , dispatch_task ):
@@ -530,7 +528,9 @@ def _dispatch_long_task(required_resources: list[str], duration=5):
530528 )
531529 wait_until ("running" , task_href )
532530 yield
533- pulpcore_bindings .TasksApi .tasks_cancel (task_href , {"state" : "canceled" })
531+ task = pulpcore_bindings .TasksApi .read (task_href )
532+ if task .state == "running" :
533+ pulpcore_bindings .TasksApi .tasks_cancel (task_href , {"state" : "canceled" })
534534
535535 return _dispatch_long_task
536536
@@ -546,16 +546,14 @@ def test_executes_in_task_worker(
546546 WHEN dispatching a task as immediate
547547 THEN the task completes with a worker
548548 """
549- COMMON_RESOURCE = "MMM"
549+ COMMON_RESOURCE = str ( uuid4 ())
550550 with dispatch_long_task (required_resources = [COMMON_RESOURCE ]):
551551 task_href = dispatch_task (
552552 "pulpcore.app.tasks.test.asleep" ,
553553 args = (LT_TIMEOUT ,),
554554 immediate = True ,
555555 exclusive_resources = [COMMON_RESOURCE ],
556556 )
557- task = pulpcore_bindings .TasksApi .read (task_href )
558- assert task .state == "waiting"
559557 task = monitor_task (task_href )
560558 assert task .state == "completed"
561559 assert task .worker is not None
@@ -569,7 +567,7 @@ def test_throws_when_non_deferrable(
569567 WHEN dispatching as immediate and not deferrable
570568 THEN an error is raised
571569 """
572- COMMON_RESOURCE = "NNN"
570+ COMMON_RESOURCE = str ( uuid4 ())
573571 with dispatch_long_task (required_resources = [COMMON_RESOURCE ]):
574572 task_href = dispatch_task (
575573 "pulpcore.app.tasks.test.asleep" ,
@@ -593,7 +591,7 @@ def test_timeouts_on_task_worker(
593591 AND it takes longer than timeout
594592 THEN an error is raised
595593 """
596- COMMON_RESOURCE = "PPP"
594+ COMMON_RESOURCE = str ( uuid4 ())
597595 with pytest .raises (PulpTaskError ) as ctx :
598596 with dispatch_long_task (required_resources = [COMMON_RESOURCE ]):
599597 task_href = dispatch_task (
@@ -602,7 +600,5 @@ def test_timeouts_on_task_worker(
602600 immediate = True ,
603601 exclusive_resources = [COMMON_RESOURCE ],
604602 )
605- task = pulpcore_bindings .TasksApi .read (task_href )
606- assert task .state == "waiting"
607603 monitor_task (task_href )
608604 assert "task timed out after" in ctx .value .task .error ["description" ]
0 commit comments