async def test_subscribe_ramp_wave(engine: Engine): query = """ subscription { subscribeChannel(id: "ssim://rampwave(3, 0.2)") { value { stringArray } } } """ context = make_context() results = [] start = time.time() async for result in engine.subscribe(query, context=context): results.append(result) if len(results) == 4: break # First result immediate, then takes 3x 0.2s assert time.time() - start - 0.6 < 0.2 expected = [ ["0.00000", "1.00000", "2.00000"], ["1.00000", "2.00000", "3.00000"], ["2.00000", "3.00000", "4.00000"], ["3.00000", "4.00000", "5.00000"], ] for i, x in enumerate(expected): assert results[i] == dict(data=dict(subscribeChannel=dict(value=dict( stringArray=x))))
async def test_subscribe_ticking(engine: Engine, ioc: Popen): query = (""" subscription { subscribeChannel(id: "ca://%sticking") { value { string(units: true) } display { precision units } } } """ % PV_PREFIX) results = [] wait_for_ioc(ioc) start = time.time() async for result in engine.subscribe(query, context=make_context()): results.append(result) if time.time() - start > 0.9: break for i, x in enumerate(range(3)): display = None if i == 0: display = dict(precision=5, units="mm") assert results[i] == dict(data=dict(subscribeChannel=dict( value=dict(string="%.5f mm" % x), display=display))) assert len(results) == 3
async def test_subscribe_sim_sine(engine: Engine): query = """ subscription { subscribeChannel(id: "ssim://sine") { value { float } } } """ context = make_context() results = [] start = time.time() async for result in engine.subscribe(query, context=context): results.append(result) if time.time() - start > 2: break for i, x in enumerate(EXPECTED_SIM_SINE): assert results[i] == dict(data=dict(subscribeChannel=dict(value=dict( float=x)))) assert len(results) == 3