Skip to content

Commit ab35384

Browse files
Correctly set alarms during blocking processing
This was an oversight in PR #202
1 parent 1711080 commit ab35384

2 files changed

Lines changed: 67 additions & 5 deletions

File tree

softioc/device.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ def set(self, value, process=True,
291291
# However if we do not process, we must do this here to keep the
292292
# Python and EPICS values in line
293293
if not process:
294+
self.process_severity(_record, severity, alarm)
294295
self._value = (value, severity, alarm)
295296

296297
db_put_field_process(_record.NAME, dbf_code, data, length, process)

tests/test_records.py

Lines changed: 66 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -684,15 +684,15 @@ def test_on_update_true_false(self, out_records):
684684
self.on_update_runner(out_records, True, False)
685685

686686
def on_update_recursive_set_test_func(
687-
self, device_name, conn
687+
self, device_name, conn, severity, alarm
688688
):
689689
log("CHILD: Child started")
690690

691691
builder.SetDeviceName(device_name)
692692

693693
async def on_update_func(new_val):
694694
log("CHILD: on_update_func started")
695-
record.set(0, process=False)
695+
record.set(0, process=False, severity=severity, alarm=alarm)
696696
conn.send("C") # "Callback"
697697
log("CHILD: on_update_func ended")
698698

@@ -718,8 +718,8 @@ async def on_update_func(new_val):
718718

719719
log("CHILD: Received exit command, child exiting")
720720

721-
async def test_on_update_recursive_set(self):
722-
"""Test that on_update functions correctly when the on_update
721+
async def test_on_update_recursive_set_value(self):
722+
"""Test that on_update sets values correctly when the on_update
723723
callback sets the value of the record again (with process=False).
724724
See issue #201"""
725725

@@ -730,7 +730,7 @@ async def test_on_update_recursive_set(self):
730730

731731
process = ctx.Process(
732732
target=self.on_update_recursive_set_test_func,
733-
args=(device_name, child_conn),
733+
args=(device_name, child_conn, alarm.NO_ALARM, alarm.NO_ALARM),
734734
)
735735

736736
process.start()
@@ -773,6 +773,67 @@ async def test_on_update_recursive_set(self):
773773
pytest.fail("Process did not terminate")
774774

775775

776+
async def test_on_update_recursive_set_alarm(self):
777+
"""Test that on_update sets alarms correctly when the on_update
778+
callback sets the value of the record again (with process=False).
779+
See issue #201"""
780+
781+
ctx = get_multiprocessing_context()
782+
parent_conn, child_conn = ctx.Pipe()
783+
784+
device_name = create_random_prefix()
785+
786+
expected_sevr = alarm.MAJOR_ALARM
787+
expected_alarm = alarm.HIGH_ALARM # arbitrary choice
788+
789+
process = ctx.Process(
790+
target=self.on_update_recursive_set_test_func,
791+
args=(device_name, child_conn, expected_sevr, expected_alarm),
792+
)
793+
794+
process.start()
795+
796+
log("PARENT: Child started, waiting for R command")
797+
798+
from aioca import caget, caput
799+
800+
try:
801+
# Wait for message that IOC has started
802+
select_and_recv(parent_conn, "R")
803+
804+
log("PARENT: received R command")
805+
806+
record = f"{device_name}:ACTION"
807+
808+
val = await caget(record)
809+
810+
assert val == 1, "ACTION record did not start with value 1"
811+
812+
await caput(record, 1, wait=True)
813+
814+
815+
sevr = await caget(record + ".SEVR")
816+
assert sevr == expected_sevr
817+
818+
sevr = await caget(record + ".STAT")
819+
assert sevr == expected_alarm
820+
821+
# Expect one "C"
822+
select_and_recv(parent_conn, "C")
823+
824+
# ...But if we receive another we know there's a problem
825+
if parent_conn.poll(5): # Shorter timeout to make this quicker
826+
pytest.fail("Received unexpected second message")
827+
828+
finally:
829+
log("PARENT:Sending Done command to child")
830+
parent_conn.send("D") # "Done"
831+
process.join(timeout=TIMEOUT)
832+
log(f"PARENT: Join completed with exitcode {process.exitcode}")
833+
if process.exitcode is None:
834+
pytest.fail("Process did not terminate")
835+
836+
776837

777838
class TestBlocking:
778839
"""Tests related to the Blocking functionality"""

0 commit comments

Comments
 (0)