Skip to content

Commit c9aeea3

Browse files
author
James Souter
committed
check initial values on softioc record wrapper instead of using flaky cagets
1 parent 48ade2d commit c9aeea3

File tree

1 file changed

+56
-55
lines changed

1 file changed

+56
-55
lines changed

tests/transport/epics/ca/test_initial_value.py

Lines changed: 56 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
import numpy as np
55
import pytest
6-
from aioca import caget
76

7+
import fastcs.transport.epics.ca.ioc as ca_ioc
88
from fastcs.attributes import AttrR, AttrRW, AttrW
99
from fastcs.controller import Controller
1010
from fastcs.datatypes import Bool, Enum, Float, Int, String, Waveform
@@ -48,68 +48,69 @@ class InitialValuesController(Controller):
4848

4949
@pytest.mark.forked
5050
@pytest.mark.asyncio
51-
async def test_initial_values_set_in_ca():
51+
async def test_initial_values_set_in_ca(mocker):
5252
pv_prefix = "SOFTIOC_INITIAL_DEVICE"
5353

5454
loop = asyncio.get_event_loop()
55+
controller = InitialValuesController()
5556
fastcs = FastCS(
56-
InitialValuesController(),
57+
controller,
5758
[EpicsCATransport(ca_ioc=EpicsIOCOptions(pv_prefix=pv_prefix))],
5859
loop,
5960
)
6061

61-
task = asyncio.create_task(fastcs.serve(interactive=False))
62-
# combine cagets to reduce timeouts
62+
record_spy = mocker.spy(ca_ioc, "_make_record")
6363

64-
# AttrRWs
65-
scalar_sets = await caget(
66-
[
67-
f"{pv_prefix}:Int",
68-
f"{pv_prefix}:Float",
69-
f"{pv_prefix}:Bool",
70-
f"{pv_prefix}:Enum",
71-
]
72-
)
73-
assert scalar_sets == [4, 3.1, 1, 1]
74-
scalar_rbvs = await caget(
75-
[
76-
f"{pv_prefix}:Int_RBV",
77-
f"{pv_prefix}:Float_RBV",
78-
f"{pv_prefix}:Bool_RBV",
79-
f"{pv_prefix}:Enum_RBV",
80-
]
81-
)
82-
assert scalar_rbvs == [4, 3.1, 1, 1]
83-
assert (await caget(f"{pv_prefix}:Str")).tobytes() == b"initial\0"
84-
assert np.array_equal((await caget(f"{pv_prefix}:Waveform")), list(range(10)))
85-
assert (await caget(f"{pv_prefix}:Str_RBV")).tobytes() == b"initial\0"
86-
assert np.array_equal((await caget(f"{pv_prefix}:Waveform_RBV")), list(range(10)))
64+
try:
65+
task = asyncio.create_task(fastcs.serve(interactive=False))
8766

88-
# AttrRs
89-
scalars = await caget(
90-
[
91-
f"{pv_prefix}:IntR",
92-
f"{pv_prefix}:FloatR",
93-
f"{pv_prefix}:BoolR",
94-
f"{pv_prefix}:EnumR",
95-
]
96-
)
97-
assert scalars == [5, 4.1, 0, 2]
98-
assert (await caget(f"{pv_prefix}:StrR")).tobytes() == b"initial_r\0"
99-
assert np.array_equal((await caget(f"{pv_prefix}:WaveformR")), list(range(10, 20)))
100-
101-
# Check AttrWs use the datatype initial value
102-
w_scalars = await caget(
103-
[
104-
f"{pv_prefix}:IntW",
105-
f"{pv_prefix}:FloatW",
106-
f"{pv_prefix}:BoolW",
107-
f"{pv_prefix}:EnumW",
108-
]
109-
)
110-
assert w_scalars == [0, 0, 0, 0]
111-
assert (await caget(f"{pv_prefix}:StrW")).tobytes() == b"\0"
112-
# initial waveforms not set with zeros
113-
assert np.array_equal((await caget(f"{pv_prefix}:WaveformW")), [])
67+
async with asyncio.timeout(3):
68+
while not record_spy.spy_return_list:
69+
await asyncio.sleep(0)
11470

115-
task.cancel()
71+
initial_values = {
72+
wrapper.name: wrapper.get() for wrapper in record_spy.spy_return_list
73+
}
74+
for name, value in {
75+
"SOFTIOC_INITIAL_DEVICE:Bool": 1,
76+
"SOFTIOC_INITIAL_DEVICE:BoolR": 0,
77+
"SOFTIOC_INITIAL_DEVICE:BoolW": 0,
78+
"SOFTIOC_INITIAL_DEVICE:Bool_RBV": 1,
79+
"SOFTIOC_INITIAL_DEVICE:Enum": 1,
80+
"SOFTIOC_INITIAL_DEVICE:EnumR": 2,
81+
"SOFTIOC_INITIAL_DEVICE:EnumW": 0,
82+
"SOFTIOC_INITIAL_DEVICE:Enum_RBV": 1,
83+
"SOFTIOC_INITIAL_DEVICE:Float": 3.1,
84+
"SOFTIOC_INITIAL_DEVICE:FloatR": 4.1,
85+
"SOFTIOC_INITIAL_DEVICE:FloatW": 0.0,
86+
"SOFTIOC_INITIAL_DEVICE:Float_RBV": 3.1,
87+
"SOFTIOC_INITIAL_DEVICE:Int": 4,
88+
"SOFTIOC_INITIAL_DEVICE:IntR": 5,
89+
"SOFTIOC_INITIAL_DEVICE:IntW": 0,
90+
"SOFTIOC_INITIAL_DEVICE:Int_RBV": 4,
91+
"SOFTIOC_INITIAL_DEVICE:Str": "initial",
92+
"SOFTIOC_INITIAL_DEVICE:StrR": "initial_r",
93+
"SOFTIOC_INITIAL_DEVICE:StrW": "",
94+
"SOFTIOC_INITIAL_DEVICE:Str_RBV": "initial",
95+
"SOFTIOC_INITIAL_DEVICE:Waveform": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
96+
"SOFTIOC_INITIAL_DEVICE:WaveformR": [
97+
10,
98+
11,
99+
12,
100+
13,
101+
14,
102+
15,
103+
16,
104+
17,
105+
18,
106+
19,
107+
],
108+
# waveforms are not zero initialised currently
109+
"SOFTIOC_INITIAL_DEVICE:WaveformW": [],
110+
"SOFTIOC_INITIAL_DEVICE:Waveform_RBV": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
111+
}.items():
112+
assert np.array_equal(value, initial_values[name])
113+
except Exception as e:
114+
raise e
115+
finally:
116+
task.cancel()

0 commit comments

Comments
 (0)