Skip to content

Commit

Permalink
Test job updated info after admin requeue
Browse files Browse the repository at this point in the history
  • Loading branch information
ammar257ammar committed Jan 10, 2025
1 parent 3cb536c commit ee7f40e
Showing 1 changed file with 81 additions and 0 deletions.
81 changes: 81 additions & 0 deletions app/tests/algorithms_tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
filter_civs_for_algorithm,
send_failed_job_notification,
)
from grandchallenge.components.admin import requeue_jobs
from grandchallenge.components.models import (
ComponentInterface,
ComponentInterfaceValue,
Expand Down Expand Up @@ -732,3 +733,83 @@ def test_archive_job_gets_gpu_and_memory_set(

assert job.requires_gpu_type == GPUTypeChoices.V100
assert job.requires_memory_gb == 1337


@pytest.mark.django_db
def test_job_updated_start_and_complete_times_after_admin_requeue(
algorithm_image, settings, django_capture_on_commit_callbacks
):
settings.task_eager_propagates = (True,)
settings.task_always_eager = (True,)

with django_capture_on_commit_callbacks() as callbacks:
ai = AlgorithmImageFactory(image=None)

with open(algorithm_image, "rb") as f:
ai.image.save(algorithm_image, ContentFile(f.read()))

recurse_callbacks(
callbacks=callbacks,
django_capture_on_commit_callbacks=django_capture_on_commit_callbacks,
)
ai.refresh_from_db()

# Make sure the job fails when trying to upload an invalid file
input_interface = ComponentInterface.objects.get(
slug="generic-medical-image"
)
detection_interface = ComponentInterfaceFactory(
store_in_database=False,
relative_path="some_text.txt",
slug="detection-json-file",
kind=ComponentInterface.Kind.ANY,
)
ai.algorithm.inputs.add(input_interface)
ai.algorithm.outputs.add(detection_interface)

image_file = ImageFileFactory(
file__from_path=Path(__file__).parent / "resources" / "input_file.tif"
)

civ = ComponentInterfaceValueFactory(
image=image_file.image, interface=input_interface, file=None
)

with django_capture_on_commit_callbacks() as callbacks:
create_algorithm_jobs(
algorithm_image=ai,
civ_sets=[{civ}],
time_limit=ai.algorithm.time_limit,
requires_gpu_type=ai.algorithm.job_requires_gpu_type,
requires_memory_gb=ai.algorithm.job_requires_memory_gb,
)
recurse_callbacks(
callbacks=callbacks,
django_capture_on_commit_callbacks=django_capture_on_commit_callbacks,
)

jobs = Job.objects.filter(
algorithm_image=ai, inputs__image=image_file.image, status=Job.FAILURE
).all()

assert len(jobs) == 1

job = jobs.first()

first_run_started_at = job.started_at
first_run_completed_at = job.completed_at

with django_capture_on_commit_callbacks() as callbacks:
requeue_jobs(None, None, jobs)

recurse_callbacks(
callbacks=callbacks,
django_capture_on_commit_callbacks=django_capture_on_commit_callbacks,
)
job.refresh_from_db()

second_run_started_at = job.started_at
second_run_completed_at = job.completed_at

assert second_run_started_at > first_run_started_at
assert second_run_completed_at > first_run_completed_at

0 comments on commit ee7f40e

Please sign in to comment.