@@ -60,6 +60,7 @@ async def test_ioc(p4p_subprocess: tuple[str, Queue]):
6060 "g" : {"rw" : f"{ pv_prefix } :Child1:G" },
6161 "h" : {"rw" : f"{ pv_prefix } :Child1:H" },
6262 "i" : {"x" : f"{ pv_prefix } :Child1:I" },
63+ "j" : {"r" : f"{ pv_prefix } :Child1:J" },
6364 }
6465
6566
@@ -104,31 +105,29 @@ async def test_scan_method(p4p_subprocess: tuple[str, Queue]):
104105
105106@pytest .mark .asyncio
106107async def test_command_method (p4p_subprocess : tuple [str , Queue ]):
107- QUEUE_TIMEOUT = 1
108- pv_prefix , stdout_queue = p4p_subprocess
108+ pv_prefix , _ = p4p_subprocess
109109 d_values = asyncio .Queue ()
110110 i_values = asyncio .Queue ()
111+ j_values = asyncio .Queue ()
111112 ctxt = Context ("pva" )
112113
113114 d_monitor = ctxt .monitor (f"{ pv_prefix } :Child1:D" , d_values .put )
114115 i_monitor = ctxt .monitor (f"{ pv_prefix } :Child1:I" , i_values .put )
116+ j_monitor = ctxt .monitor (f"{ pv_prefix } :Child1:J" , j_values .put )
115117
116118 try :
117- if not stdout_queue .empty ():
118- raise RuntimeError ("stdout_queue not empty" , stdout_queue .get ())
119+ j_initial_value = await j_values .get ()
119120 assert (await d_values .get ()).raw .value is False
120121 await ctxt .put (f"{ pv_prefix } :Child1:D" , True )
121122 assert (await d_values .get ()).raw .value is True
123+ # D process hangs for 0.1s, so we wait slightly longer
122124 await asyncio .sleep (0.2 )
125+ # Value returns to False, signifying completed process
123126 assert (await d_values .get ()).raw .value is False
124-
125- assert stdout_queue .get (timeout = QUEUE_TIMEOUT ) == "D: RUNNING"
126- assert stdout_queue .get (timeout = QUEUE_TIMEOUT ) == "\n "
127- assert stdout_queue .get (timeout = QUEUE_TIMEOUT ) == "D: FINISHED"
128- assert stdout_queue .get (timeout = QUEUE_TIMEOUT ) == "\n "
127+ # D process increments J by 1
128+ assert (await j_values .get ()).raw .value == j_initial_value + 1
129129
130130 # First run fails
131- assert stdout_queue .empty ()
132131 before_command_value = (await i_values .get ()).raw
133132 assert before_command_value ["value" ] is False
134133 assert before_command_value ["alarm" ]["severity" ] == 0
@@ -143,30 +142,26 @@ async def test_command_method(p4p_subprocess: tuple[str, Queue]):
143142 assert (
144143 after_command_value ["alarm" ]["message" ] == "I: FAILED WITH THIS WEIRD ERROR"
145144 )
146- assert stdout_queue . get ( timeout = QUEUE_TIMEOUT ) == "I: RUNNING"
147- assert stdout_queue . get ( timeout = QUEUE_TIMEOUT ) == " \n "
145+ # Failed I process does not increment J
146+ assert j_values . empty ()
148147
149148 # Second run succeeds
150- assert stdout_queue .empty ()
151149 await ctxt .put (f"{ pv_prefix } :Child1:I" , True )
152150 assert (await i_values .get ()).raw .value is True
153151 await asyncio .sleep (0.2 )
154152 after_command_value = (await i_values .get ()).raw
153+ # Successful I process increments J by 1
154+ assert (await j_values .get ()).raw .value == j_initial_value + 2
155155
156156 # On the second run the command succeeded so we left the error state
157157 assert after_command_value ["value" ] is False
158158 assert after_command_value ["alarm" ]["severity" ] == 0
159159 assert after_command_value ["alarm" ]["message" ] == ""
160160
161- assert stdout_queue .get (timeout = QUEUE_TIMEOUT ) == "I: RUNNING"
162- assert stdout_queue .get (timeout = QUEUE_TIMEOUT ) == "\n "
163- assert stdout_queue .get (timeout = QUEUE_TIMEOUT ) == "I: FINISHED"
164- assert stdout_queue .get (timeout = QUEUE_TIMEOUT ) == "\n "
165- assert stdout_queue .empty ()
166-
167161 finally :
168162 d_monitor .close ()
169163 i_monitor .close ()
164+ j_monitor .close ()
170165
171166
172167@pytest .mark .asyncio
0 commit comments