def test_same_hdr_many_times(hw, RE): source = Stream() fes1 = FromEventStream("start", ("number",), source, principle=True) fes2 = FromEventStream("event", ("data", "motor"), source, principle=True) out1 = fes1.map(op.add, 1) out2 = fes2.combine_latest(out1, emit_on=0).starmap(op.mul) a = ToEventStream(out1, ("out1",)) b = ToEventStream(out2, ("out2",)) la = a.sink_to_list() lb = b.sink_to_list() L = [] RE.subscribe(lambda *x: L.append(x)) RE(count([hw.motor], md={"number": 5})) for i in range(1, 3): for ll in L: source.emit(ll) for lst in [la, lb]: o1 = [z[0] for z in lst] o2 = ["start", "descriptor", "event", "stop"] * i assert o1 == o2
def test_slow_to_event_model(): """This doesn't use threads so it should be slower due to sleep""" source = Stream(asynchronous=True) t = FromEventStream("event", ("data", "det_image"), source, principle=True) assert t.principle a = t.map(slow_inc) L = a.sink_to_list() futures_L = a.sink_to_list() n = a.SimpleToEventStream(("ct", )) n.sink(print) tt = t.sink_to_list() p = n.pluck(0).sink_to_list() d = n.pluck(1).sink_to_list() t0 = time.time() for gg in y(10): yield source.emit(gg) while len(L) < len(futures_L): yield gen.sleep(.01) t1 = time.time() # check that this was faster than running in series td = t1 - t0 ted = .5 * 10 assert td > ted assert tt assert p == ["start", "descriptor"] + ["event"] * 10 + ["stop"] assert d[1]["hints"] == {"analyzer": {"fields": ["ct"]}}