Changeset View
Changeset View
Standalone View
Standalone View
swh/scheduler/tests/test_scheduler.py
Show First 20 Lines • Show All 109 Lines • ▼ Show 20 Lines | def test_create_tasks(self, swh_scheduler): | ||||
TEMPLATES["hg"], | TEMPLATES["hg"], | ||||
utcnow(), | utcnow(), | ||||
100, | 100, | ||||
num_tasks_priority, | num_tasks_priority, | ||||
priorities=priority_ratio, | priorities=priority_ratio, | ||||
) | ) | ||||
tasks = tasks_1 + tasks_2 | tasks = tasks_1 + tasks_2 | ||||
assert len(tasks_1) > 0 | |||||
assert len(tasks_2) > 0 | |||||
# tasks are returned only once with their ids | # tasks are returned only once with their ids | ||||
ret1 = swh_scheduler.create_tasks(tasks + tasks_1 + tasks_2) | ret1 = swh_scheduler.create_tasks(tasks + tasks_1 + tasks_2) | ||||
set_ret1 = set([t["id"] for t in ret1]) | set_ret1 = set([t["id"] for t in ret1]) | ||||
# creating the same set result in the same ids | # creating the same set result in the same ids | ||||
ret = swh_scheduler.create_tasks(tasks) | ret = swh_scheduler.create_tasks(tasks) | ||||
set_ret = set([t["id"] for t in ret]) | set_ret = set([t["id"] for t in ret]) | ||||
Show All 10 Lines | def test_create_tasks(self, swh_scheduler): | ||||
assert task["id"] not in ids | assert task["id"] not in ids | ||||
assert task["status"] == "next_run_not_scheduled" | assert task["status"] == "next_run_not_scheduled" | ||||
assert task["current_interval"] == task_type["default_interval"] | assert task["current_interval"] == task_type["default_interval"] | ||||
assert task["policy"] == orig_task.get("policy", "recurring") | assert task["policy"] == orig_task.get("policy", "recurring") | ||||
priority = task.get("priority") | priority = task.get("priority") | ||||
if priority: | if priority: | ||||
actual_priorities[priority] += 1 | actual_priorities[priority] += 1 | ||||
try: | |||||
assert task["retries_left"] == (task_type["num_retries"] or 0) | assert task["retries_left"] == (task_type["num_retries"] or 0) | ||||
except AssertionError: | |||||
pass # import pdb; pdb.set_trace() | |||||
ids.add(task["id"]) | ids.add(task["id"]) | ||||
del task["id"] | del task["id"] | ||||
del task["status"] | del task["status"] | ||||
del task["current_interval"] | del task["current_interval"] | ||||
del task["retries_left"] | del task["retries_left"] | ||||
if "policy" not in orig_task: | if "policy" not in orig_task: | ||||
del task["policy"] | del task["policy"] | ||||
if "priority" not in orig_task: | if priority: | ||||
# task with priority have no more priority in the backend | |||||
assert task["priority"] is None | |||||
# and are redirected to their respective high priority queues | |||||
assert task["type"] == f"{orig_task['type']}-high" | |||||
else: | |||||
del task["priority"] | del task["priority"] | ||||
assert task == orig_task | assert task == orig_task | ||||
# the priority ratio distributions are in effect moot now | |||||
# that will be cleaned up at some point in the future | |||||
assert dict(actual_priorities) == { | assert dict(actual_priorities) == { | ||||
priority: int(ratio * num_tasks_priority) | priority: 0 for priority, _ in priority_ratio.items() | ||||
for priority, ratio in priority_ratio.items() | |||||
} | } | ||||
def test_peek_ready_tasks_no_priority(self, swh_scheduler): | def test_peek_ready_tasks_no_priority(self, swh_scheduler): | ||||
self._create_task_types(swh_scheduler) | self._create_task_types(swh_scheduler) | ||||
t = utcnow() | t = utcnow() | ||||
task_type = TEMPLATES["git"]["type"] | task_type = TEMPLATES["git"]["type"] | ||||
tasks = tasks_from_template(TEMPLATES["git"], t, 100) | tasks = tasks_from_template(TEMPLATES["git"], t, 100) | ||||
random.shuffle(tasks) | random.shuffle(tasks) | ||||
▲ Show 20 Lines • Show All 1,095 Lines • Show Last 20 Lines |