def test_asynctll(): loop = asynctll.Loop() async def main(): ctx = C.Context() s = ctx.Channel("mem://;size=1kb;name=server;dump=yes") c = ctx.Channel("mem://;master=server;name=client;dump=yes") loop.channel_add(s) loop.channel_add(c) s.open() c.open() s.post(b'xxx', seq=100) m = await loop.recv(c) loop.log.info("Got message {}", m) assert m.seq == 100 assert m.data == b'xxx' s.post(b'zzz', seq=200) m = await loop.recv(c) assert m.seq == 200 assert m.data == b'zzz' loop.run(main())
def test_logic_async_func(): ctx = C.Context() ctx.register(TestLogic) loop = asynctll.Loop(ctx) async def main(loop): i, o = loop.Channel('direct://;name=test/input'), loop.Channel( 'direct://;name=test/output') li, lo = loop.Channel( 'direct://;name=input;master=test/input'), loop.Channel( 'direct://;name=output;master=test/output') i.open(), o.open() li.open(), lo.open() logic = loop.Channel( 'logic://;name=logic;tll.channel.input=input;tll.channel.output=output' ) logic.open() i.post(b'xxx', seq=10) i.post(b'zzz', seq=20) m = await o.recv() assert m.data.tobytes() == b'xxx' assert m.seq == 10 m = await o.recv() assert m.data.tobytes() == b'zzz' assert m.seq == 20 loop.run(main(loop))
def test_sleep(): loop = asynctll.Loop(context=C.Context()) async def main(loop): print("Sleep start") await loop.sleep(0.001) print("Sleep next") await loop.sleep(0.001) print("Sleep next") await loop.sleep(0.001) print("Sleep done") loop.run(main(loop))
def test_direct_recv(): loop = asynctll.Loop(context=C.Context()) async def main(loop): s = loop.Channel('direct://;name=server;dump=frame') c = loop.Channel('direct://;name=client;dump=frame', master=s) s.open() c.open() c.post(b'xxx', seq=0) start = time.time() m = await s.recv(0.1) dt = time.time() - start assert dt < 0.001 loop.run(main(loop))
def setup(self): self.ctx = Context() self.ctx.load( os.path.join(os.environ.get("BUILD_DIR", "build"), "tll-uws"), 'channel_module') self.loop = asynctll.Loop(context=self.ctx) self.server = self.loop.Channel('ws://*:8080', name='server') self.thread_event = self.loop.Channel("direct://", name='thread/tll', dump='text') self.main_event = self.ctx.Channel("direct://", name='thread/main', master=self.thread_event) self.channels = [] self.thread = None self.thread_stop = threading.Event() self.thread_error = None self.thread_event.open() self.main_event.open()
def setup_method(self): self.channels = {} self.ctx = C.Context() self.loop = asynctll.Loop(self.ctx) channels = set() for k, l in self.CHANNELS.items(): if not l: continue for c in [x.strip() for x in l.split(',')]: if c == '': raise ValueError("Empty channel name in '{}'", l) channels.add(c) kw = {} if self.SCHEME: kw['scheme'] = self.SCHEME for c in channels: self.channels['test/' + c] = self.loop.Channel( 'direct://;name=test/{name}'.format(name=c), **kw) self.channels[c] = self.loop.Channel( 'direct://;name={name};master=test/{name}'.format(name=c), **kw) for n, c in self.channels.items(): if n.startswith('test/'): c.open()
def test_nofd(): loop = asynctll.Loop(context=C.Context()) async def main(loop): s = loop.Channel("mem://;size=1kb;name=server;dump=yes;fd=no") c = loop.Channel("mem://;master=server;name=client;dump=yes") s.open() c.open() s.post(b'xxx', seq=100) m = await c.recv() loop.log.info("Got message {}", m) assert m.seq == 100 assert m.data == b'xxx' s.post(b'zzz', seq=200) m = await loop.recv(c) # Mixed syntax assert m.seq == 200 assert m.data == b'zzz' loop.run(main(loop))
def asyncloop(context): loop = asynctll.Loop(context) yield loop loop.destroy() loop = None