Skip to content

Commit

Permalink
Change the way we setup the test, and also add some comments.
Browse files Browse the repository at this point in the history
Close #3821
  • Loading branch information
decko committed May 3, 2024
1 parent 45ca91a commit 1c84817
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions pulpcore/tests/functional/api/test_tasking.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,28 +360,26 @@ def test_task_version_prevent_pickup(dispatch_task, pulpcore_bindings):
def test_emmiting_unblocked_task_telemetry(
dispatch_task, pulpcore_bindings, pulp_settings, received_otel_metrics
):
if not os.getenv("PULP_OTEL_ENABLED"):
if os.getenv("PULP_OTEL_ENABLED").lower() != "true":
pytest.skip("Need PULP_OTEL_ENABLED to run this test.")

expected_heartbeat = timezone.now() - timedelta(seconds=pulp_settings.WORKER_TTL)
# Checking online workers ready to get a task
age_threshold = timezone.now() - timedelta(seconds=pulp_settings.WORKER_TTL)
workers_online = pulpcore_bindings.WorkersApi.list(last_heartbeat__gte=age_threshold).count

workers_count = pulpcore_bindings.WorkersApi.list(last_heartbeat__gte=expected_heartbeat).count

resource = str(uuid4())

for worker in range(workers_count):
dispatch_task("pulpcore.app.tasks.test.sleep", args=(100,), exclusive_resources=[resource])

task_href = dispatch_task(
"pulpcore.app.tasks.test.sleep", args=(0,), exclusive_resources=[resource]
)
# We need to generate long running tasks to block the workers from executing other tasks
for worker in range(workers_online + 1):
dispatch_task(
"pulpcore.app.tasks.test.sleep", args=(30,), exclusive_resources=[str(uuid4())]
)

for dummy in range(workers_count * 5):
dispatch_task("pulpcore.app.tasks.test.sleep", args=(0,), exclusive_resources=[resource])
# Then we dispatch a quick unblockable task just to keep it waiting in the queue
task_href = dispatch_task("pulpcore.app.tasks.test.sleep", args=(0,))

task = pulpcore_bindings.TasksApi.read(task_href)
assert task.state == "waiting"

# And trigger the metrics
assert received_otel_metrics(
{
"name": "tasks_unblocked_queue",
Expand Down

0 comments on commit 1c84817

Please sign in to comment.