Skip to content
Snippets Groups Projects
Unverified Commit 699e1cc8 authored by Antoine R. Dumont's avatar Antoine R. Dumont
Browse files

scheduler/runner-first-visits: Adapt properly tests

Use the caplog fixture to check the cli output messages.

Refs. swh/devel/swh-scheduler#4687
parent a52c68db
No related branches found
No related tags found
No related merge requests found
Pipeline #11467 failed
......@@ -243,8 +243,6 @@ def runner_first_visits(ctx, period):
from swh.scheduler.celery_backend.first_visits import schedule_first_visits
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__ + ".runner_first_visits")
scheduler: SchedulerInterface = ctx.obj["scheduler"]
......
# Copyright (C) 2021-2024 The Software Heritage developers
# Copyright (C) 2024 The Software Heritage developers
# See the AUTHORS file at the top-level directory of this distribution
# License: GNU General Public License version 3, or any later version
# See top-level LICENSE file for more information
from datetime import timedelta
import logging
from typing import Tuple
from swh.scheduler.model import ListedOrigin, OriginVisitStats
......@@ -20,9 +21,19 @@ def invoke(
)
MODULE_NAME = "swh.scheduler.cli.admin"
def test_runner_high_priority_first_visits(
swh_scheduler, swh_scheduler_celery_app, visit_types, task_types, mocker
swh_scheduler,
swh_scheduler_celery_app,
visit_types,
task_types,
mocker,
caplog,
):
caplog.set_level(logging.INFO, MODULE_NAME)
nb_origins_per_visit_type = 10
# number of celery queue slots per visit type is lower than the
# number of listed origins for that visit type
......@@ -74,37 +85,48 @@ def test_runner_high_priority_first_visits(
# start scheduling first visits
result = invoke(swh_scheduler, args=("start-runner-first-visits",))
assert result.exit_code == 0
records = [record.message for record in caplog.records]
# check expected number of visits were scheduled
for visit_type in visit_types:
assert (
f"{nb_available_queue_slots} visits of type {visit_type} to send to celery"
in result.stdout
in records
)
# check there is still origin first visits to schedule
assert (
f"All first visits of origins registered by lister with name '{lister_name}' "
f"and instance '{lister_instance_name}' were scheduled.'"
) not in result.stdout
) not in records
lister = swh_scheduler.get_lister(
name=lister_name, instance_name=lister_instance_name
)
assert lister.first_visits_scheduled_at is None
# Reset the logs for the next cli call
caplog.clear()
# continue scheduling first visits
result = invoke(swh_scheduler, args=("start-runner-first-visits",))
assert result.exit_code == 0
records = [record.message for record in caplog.records]
# check expected number of visits were scheduled
for visit_type in visit_types:
assert (
f"{nb_available_queue_slots} visits of type {visit_type} to send to celery"
in result.stdout
in records
)
# check all listed origins first visits were scheduled
assert (
f"All first visits of origins registered by lister with name '{lister_name}' "
f"and instance '{lister_instance_name}' were scheduled.'"
) in result.stdout
) in records
lister = swh_scheduler.get_lister(
name=lister_name, instance_name=lister_instance_name
)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment