def test_telepath_events(self): with s_daemon.Daemon() as dmon: with s_service.SvcBus() as sbus: urlt = 'tcp://127.0.0.1:%d' url = urlt % (0) link = dmon.listen(url) port = link[1].get('port') url = urlt % (port) dmon.share('sbus', sbus) proxy0 = s_telepath.openurl(url + '/sbus') proxy1 = s_telepath.openurl(url + '/sbus') counters = [0, 0] def count(offset): def on(*args, **kwargs): counters[offset] += 1 return on proxy0.on('tufo:tag:add', count(0)) proxy1.on('tufo:tag:add', count(1)) wait = s_eventbus.Waiter(proxy1, 1, 'tufo:tag:add') proxy0.fire('tufo:tag:add', tag='tagu', tufo=('iden', { 'prop': 'valu' })) wait.wait() self.assertEqual(counters[0], 1) self.assertEqual(counters[1], 1)
def test_threads_pool_wrap(self): pool = s_threads.Pool() wait = s_eventbus.Waiter(pool, 1, 'pool:work:fini') def woot(x, y): return x + y pool.wrap(woot)(20, 30) wait.wait() pool.fini()
def test_threads_pool(self): pool = s_threads.Pool() wait = s_eventbus.Waiter(pool, 1, 'pool:work:fini') def woot(x, y): return x + y pool.task(newtask(woot, 20, 30)) wait.wait() pool.fini()
def getTestWait(self, bus, size, *evts): return s_eventbus.Waiter(bus, size, *evts)