Skip to content

Commit

Permalink
Add test for ExtractionJobTracker machinery
Browse files Browse the repository at this point in the history
  • Loading branch information
takluyver committed Dec 18, 2024
1 parent 165e1f1 commit dd59ef8
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions tests/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import subprocess
import textwrap
from time import sleep, time
from uuid import uuid4
from unittest.mock import MagicMock, patch

import extra_data as ed
Expand All @@ -25,6 +26,7 @@
from damnit.backend import backend_is_running, initialize_and_start_backend
from damnit.backend.db import DamnitDB
from damnit.backend.extract_data import Extractor, RunExtractor, add_to_db
from damnit.backend.extraction_control import ExtractionJobTracker
from damnit.backend.listener import (MAX_CONCURRENT_THREADS, EventProcessor,
local_extraction_threads)
from damnit.backend.supervisord import wait_until, write_supervisord_conf
Expand Down Expand Up @@ -903,3 +905,32 @@ def test_event_processor(mock_db, caplog):

assert len(local_extraction_threads) == MAX_CONCURRENT_THREADS
assert 'Too many events processing' in caplog.text


def test_job_tracker():
tracker = ExtractionJobTracker()

d = {'proposal': 1234, 'data': 'all', 'hostname': '', 'username': '',
'slurm_cluster': '', 'slurm_job_id': ''}

prid1, prid2 = str(uuid4()), str(uuid4())

# Add two running jobs
tracker.on_processing_running(d | {'run': 1, 'processing_id': prid1})
tracker.on_processing_running(d | {
'run': 2, 'processing_id': prid2,
'slurm_cluster': 'maxwell', 'slurm_job_id': '321'
})
assert set(tracker.jobs) == {prid1, prid2}

# One job finishes normally
tracker.on_processing_finished({'processing_id': prid1})
assert set(tracker.jobs) == {prid2}

# The other one fails to send a finished message, so checking Slurm reveals
# that it failed.
with MockCommand.fixed_output('squeue', '') as fake_squeue:
tracker.check_slurm_jobs()

fake_squeue.assert_called()
assert set(tracker.jobs) == set()

0 comments on commit dd59ef8

Please sign in to comment.