Skip to content

Commit

Permalink
Add test for processing status indicators
Browse files Browse the repository at this point in the history
  • Loading branch information
takluyver committed Aug 29, 2024
1 parent 5b61316 commit 7465b17
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
4 changes: 4 additions & 0 deletions damnit/gui/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -633,12 +633,16 @@ def handle_processing_started(self, info):
processing_id = info['processing_id']
self.processing_jobs[processing_id] = info
self.update_processing_status(info['proposal'], info['run'])
log.debug("Processing started for p%s r%s on %s (%s)",
info['proposal'], info['run'], info['hostname'], processing_id)

def handle_processing_finished(self, info):
processing_id = info['processing_id']
info = self.processing_jobs.pop(processing_id, None)
if info is not None:
self.update_processing_status(info['proposal'], info['run'])
log.debug("Processing finished for p%s r%s (%s)",
info['proposal'], info['run'], processing_id)

def update_processing_status(self, proposal, run):
"""Show/hide the processing indicator for the given run"""
Expand Down
30 changes: 30 additions & 0 deletions tests/test_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from pathlib import Path
from unittest.mock import patch
from types import SimpleNamespace
from uuid import uuid4

import h5py
import pytest
Expand Down Expand Up @@ -951,3 +952,32 @@ def test_precreate_runs(mock_db_with_data, qtbot, monkeypatch):
win.precreate_runs_dialog()
dialog.assert_called_once()
assert get_n_runs() == n_runs + 1

def test_processing_status(mock_db_with_data, qtbot):
db_dir, db = mock_db_with_data
win = MainWindow(db_dir, connect_to_kafka=False)
qtbot.addWidget(win)
tbl = win.table

def shows_as_processing(run):
row = tbl.find_row(1234, run)
runnr_s = tbl.item(row, 2).data(Qt.ItemDataRole.DisplayRole)
return "⚙️" in runnr_s

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

# Test with an existing run
prid1, prid2 = str(uuid4()), str(uuid4())
tbl.handle_processing_started(d | {'run': 1, 'processing_id': prid1})
assert shows_as_processing(1)
tbl.handle_processing_started(d | {'run': 1, 'processing_id': prid2})
tbl.handle_processing_finished({'processing_id': prid1})
assert shows_as_processing(1)
tbl.handle_processing_finished({'processing_id': prid2})
assert not shows_as_processing(1)

# Processing starting for a new run should add a row
assert tbl.rowCount() == 1
tbl.handle_processing_started(d | {'run': 2, 'processing_id': str(uuid4())})
assert tbl.rowCount() == 2
assert shows_as_processing(2)

0 comments on commit 7465b17

Please sign in to comment.