Skip to content

Commit

Permalink
Increased waiting time in flaky task schedule test
Browse files Browse the repository at this point in the history
fixes #5420
  • Loading branch information
mdellweg committed May 28, 2024
1 parent 21b57bb commit 778108a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGES/5420.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Increased the waiting time for the scheduled task in its corresponding test, because the latter was flaky.
23 changes: 12 additions & 11 deletions pulpcore/tests/functional/api/test_workers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@


@pytest.mark.parallel
def test_worker_actions(workers_api_client):
def test_worker_actions(pulpcore_bindings):
# Read all workers.
workers = workers_api_client.list().results
workers = pulpcore_bindings.WorkersApi.list().results
for worker in workers:
for key, val in worker.to_dict().items():
if key in _DYNAMIC_WORKER_ATTRS:
Expand All @@ -26,14 +26,14 @@ def test_worker_actions(workers_api_client):
chosen_worker = choice(workers)

# Read a worker by its pulp_href.
read_worker = workers_api_client.read(chosen_worker.pulp_href)
read_worker = pulpcore_bindings.WorkersApi.read(chosen_worker.pulp_href)
for key, val in chosen_worker.to_dict().items():
if key in _DYNAMIC_WORKER_ATTRS:
continue
assert getattr(read_worker, key) == val

# Read a worker by its name.
response = workers_api_client.list(name=chosen_worker.name)
response = pulpcore_bindings.WorkersApi.list(name=chosen_worker.name)
assert response.count == 1
found_worker = response.results[0]
for key, val in chosen_worker.to_dict().items():
Expand All @@ -42,7 +42,7 @@ def test_worker_actions(workers_api_client):
assert getattr(found_worker, key) == val

# Read a worker using a set of query parameters.
response = workers_api_client.list(
response = pulpcore_bindings.WorkersApi.list(
**{
"last_heartbeat__gte": chosen_worker.last_heartbeat,
"name": chosen_worker.name,
Expand All @@ -56,7 +56,7 @@ def test_worker_actions(workers_api_client):
assert getattr(found_worker, key) == val

# Read a worker with a query that does not match any worker.
response = workers_api_client.list(
response = pulpcore_bindings.WorkersApi.list(
**{
"last_heartbeat__gte": str(datetime.now() + timedelta(days=1)),
"name": chosen_worker.name,
Expand All @@ -66,7 +66,7 @@ def test_worker_actions(workers_api_client):

# Use an HTTP method different than GET
with pytest.raises(AttributeError):
workers_api_client.delete(chosen_worker.pulp_href)
pulpcore_bindings.WorkersApi.delete(chosen_worker.pulp_href)


@pytest.fixture(params=[None, 100])
Expand Down Expand Up @@ -99,22 +99,23 @@ def task_schedule(request):


@pytest.mark.parallel
def test_task_schedule(task_schedule, task_schedules_api_client):
def test_task_schedule(task_schedule, pulpcore_bindings):
"""Test that a worker will schedule a task roughly at a given time."""
# Worker TTL is configured to 30s, therefore they will have a heartbeat each 10s (6 bpm). The
# task is scheduled 5s in the future to give us time to invesitgate the state before and after.
# 16s later we can be sure it was scheduled (as long as at least one worker is running).
# Waiting for 18s to give some more slack.

result = task_schedules_api_client.list(name=task_schedule["name"])
result = pulpcore_bindings.TaskSchedulesApi.list(name=task_schedule["name"])
assert result.count == 1
ts = result.results[0]
assert ts.name == task_schedule["name"]
assert ts.task_name == task_schedule["task_name"]
assert ts.last_task is None
# At least a worker heartbeat is needed
for i in range(16):
for i in range(18):
sleep(1)
ts = task_schedules_api_client.read(task_schedule_href=ts.pulp_href)
ts = pulpcore_bindings.TaskSchedulesApi.read(task_schedule_href=ts.pulp_href)
if ts.last_task is not None:
break
assert ts.last_task is not None
Expand Down

0 comments on commit 778108a

Please sign in to comment.