Skip to content

Commit

Permalink
seq.py: Check generate_scan process started
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianJKoopman committed Dec 18, 2023
1 parent e37cd59 commit edb66d8
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
6 changes: 2 additions & 4 deletions src/sorunlib/seq.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import sorunlib as run
from sorunlib._internal import check_response
from sorunlib._internal import check_response, check_started


OP_TIMEOUT = 60
Expand Down Expand Up @@ -41,9 +41,7 @@ def scan(description, stop_time, width, az_drift=0, tag=None, subtype=None):
el_endpoint2=el,
el_speed=0,
az_drift=az_drift)

if not resp.session:
raise Exception(f"Generate Scan failed to start:\n {resp}")
check_started(acu, resp)

# Wait until stop time
run.commands.wait_until(stop_time)
Expand Down
35 changes: 33 additions & 2 deletions tests/test_seq.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
os.environ["SORUNLIB_CONFIG"] = "./data/example_config.yaml"
import datetime as dt

import ocs
import pytest
from unittest.mock import MagicMock, patch
from ocs.ocs_client import OCSReply

import sorunlib
from sorunlib import seq

from util import create_patch_clients
from util import create_patch_clients, create_session


patch_clients = create_patch_clients('satp')
Expand All @@ -22,7 +24,7 @@ def test_scan(patch_clients):


@patch('sorunlib.commands.time.sleep', MagicMock())
def test_scan_failed_to_start(patch_clients):
def test_scan_no_session(patch_clients):
# Setup mock OCSReply without session object
mock_reply = MagicMock()
mock_reply.session = None
Expand All @@ -31,3 +33,32 @@ def test_scan_failed_to_start(patch_clients):
target = dt.datetime.now() + dt.timedelta(seconds=1)
with pytest.raises(Exception):
seq.scan(description='test', stop_time=target.isoformat(), width=20.)


@patch('sorunlib.commands.time.sleep', MagicMock())
def test_scan_failed_to_start(patch_clients):
# Setup mock OCSReply with failed status
failed_session = create_session('generate_scan')
failed_session.success = False
failed_session.set_status('running')
failed_session.add_message('A simulated error has occurred.')
failed_session.set_status('done')

mock_reply = OCSReply(ocs.OK, 'msg', failed_session.encoded())
sorunlib.CLIENTS['acu'].generate_scan.start = MagicMock(return_value=mock_reply)
sorunlib.CLIENTS['acu'].generate_scan.wait = MagicMock(return_value=mock_reply)

# Example of failed reply this is trying to emulate.
# OCSReply: OK : Operation "generate_scan" is currently not running (FAILED).
# generate_scan[session=15]; status=done with ERROR 116.5 s ago, took 68.8 s
# messages (4 of 4):
# 1702337679.564 Status is now "starting".
# 1702337679.565 Status is now "running".
# 1702337748.356 Problems during scan
# 1702337748.357 Status is now "done".
# other keys in .session: op_code, data
print(mock_reply)

target = dt.datetime.now() + dt.timedelta(seconds=1)
with pytest.raises(RuntimeError):
seq.scan(description='test', stop_time=target.isoformat(), width=20.)

0 comments on commit edb66d8

Please sign in to comment.