@@ -683,16 +683,16 @@ def test_on_update_true_false(self, out_records):
683683 always_update is True and the put'ed value is always different"""
684684 self .on_update_runner (out_records , True , False )
685685
686- def on_update_recursive_set_test_func (
687- self , device_name , conn , severity , alarm
686+ def on_update_recursive_set_value_test_func (
687+ self , device_name , conn ,
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 , severity = severity , alarm = alarm )
695+ record .set (0 , process = False )
696696 conn .send ("C" ) # "Callback"
697697 log ("CHILD: on_update_func ended" )
698698
@@ -729,8 +729,8 @@ async def test_on_update_recursive_set_value(self):
729729 device_name = create_random_prefix ()
730730
731731 process = ctx .Process (
732- target = self .on_update_recursive_set_test_func ,
733- args = (device_name , child_conn , alarm . NO_ALARM , alarm . NO_ALARM ),
732+ target = self .on_update_recursive_set_value_test_func ,
733+ args = (device_name , child_conn ),
734734 )
735735
736736 process .start ()
@@ -773,10 +773,48 @@ async def test_on_update_recursive_set_value(self):
773773 pytest .fail ("Process did not terminate" )
774774
775775
776+ def on_update_recursive_set_alarm_test_func (
777+ self , device_name , conn , severity , alrm
778+ ):
779+ log ("CHILD: Child started" )
780+
781+ builder .SetDeviceName (device_name )
782+
783+ async def on_update_func (new_val ):
784+ log (f"CHILD: on_update_func started value { new_val } " )
785+ if new_val == 2 :
786+ record .set (new_val , process = False , severity = severity , alarm = alrm )
787+ elif new_val == 3 :
788+ record .set (new_val , process = False , severity = alarm .NO_ALARM , alarm = alarm .NO_ALARM )
789+ conn .send ("C" ) # "Callback"
790+ log ("CHILD: on_update_func ended" )
791+
792+ record = builder .longOut (
793+ "ACTION" ,
794+ on_update = on_update_func ,
795+ blocking = True ,
796+ initial_value = 1 # A non-zero value, to check it changes
797+ )
798+
799+ dispatcher = asyncio_dispatcher .AsyncioDispatcher ()
800+ builder .LoadDatabase ()
801+ softioc .iocInit (dispatcher )
802+
803+ conn .send ("R" ) # "Ready"
804+
805+ log ("CHILD: Sent R over Connection to Parent" )
806+
807+ # Keep process alive while main thread runs CAGET
808+ if conn .poll (TIMEOUT ):
809+ val = conn .recv ()
810+ assert val == "D" , "Did not receive expected Done character"
811+
812+ log ("CHILD: Received exit command, child exiting" )
813+
776814 async def test_on_update_recursive_set_alarm (self ):
777815 """Test that on_update sets alarms correctly when the on_update
778816 callback sets the value of the record again (with process=False).
779- See issue #201 """
817+ See PR #209 """
780818
781819 ctx = get_multiprocessing_context ()
782820 parent_conn , child_conn = ctx .Pipe ()
@@ -787,7 +825,7 @@ async def test_on_update_recursive_set_alarm(self):
787825 expected_alarm = alarm .HIGH_ALARM # arbitrary choice
788826
789827 process = ctx .Process (
790- target = self .on_update_recursive_set_test_func ,
828+ target = self .on_update_recursive_set_alarm_test_func ,
791829 args = (device_name , child_conn , expected_sevr , expected_alarm ),
792830 )
793831
@@ -809,8 +847,8 @@ async def test_on_update_recursive_set_alarm(self):
809847
810848 assert val == 1 , "ACTION record did not start with value 1"
811849
812- await caput ( record , 1 , wait = True )
813-
850+ # Trigger callback to set alarm states
851+ await caput ( record , 2 , wait = True )
814852
815853 sevr = await caget (record + ".SEVR" )
816854 assert sevr == expected_sevr
@@ -821,6 +859,18 @@ async def test_on_update_recursive_set_alarm(self):
821859 # Expect one "C"
822860 select_and_recv (parent_conn , "C" )
823861
862+ # Trigger another callback to clear alarm states
863+ await caput (record , 3 , wait = True )
864+
865+ sevr = await caget (record + ".SEVR" )
866+ assert sevr == alarm .NO_ALARM
867+
868+ sevr = await caget (record + ".STAT" )
869+ assert sevr == alarm .NO_ALARM
870+
871+ # Expect second "C"
872+ select_and_recv (parent_conn , "C" )
873+
824874 # ...But if we receive another we know there's a problem
825875 if parent_conn .poll (5 ): # Shorter timeout to make this quicker
826876 pytest .fail ("Received unexpected second message" )
0 commit comments