def test_service_base(self): sbus = s_service.SvcBus() dmon = s_daemon.Daemon() dmon.share('syn.svcbus', sbus) link = dmon.listen('tcp://127.0.0.1:0/') port = link[1].get('port') prox = s_telepath.openurl('tcp://127.0.0.1/syn.svcbus', port=port) woot = Woot() s_service.runSynSvc('syn.woot', woot, prox) svcs = prox.getSynSvcs() self.assertEqual( len(svcs), 1 ) self.assertEqual( svcs[0][1].get('name'), 'syn.woot' ) dyntask = s_async.newtask('foo',10,y=30) job = prox.callx(svcs[0][0], dyntask) self.assertEqual( prox.sync(job), 40 ) prox.fini() dmon.fini() sbus.fini()
def test_service_base(self): with s_daemon.Daemon() as dmon: sbus = s_service.SvcBus() dmon.share('syn.svcbus', sbus, fini=True) link = dmon.listen('tcp://127.0.0.1:0/') port = link[1].get('port') with s_telepath.openurl('tcp://127.0.0.1/syn.svcbus', port=port) as prox: woot = Woot() s_service.runSynSvc('syn.woot', woot, prox) svcs = prox.getSynSvcs() self.eq(len(svcs), 1) self.eq(svcs[0][1].get('name'), 'syn.woot') dyntask = s_async.newtask('foo', 10, y=30) job = prox.callx(svcs[0][0], dyntask) self.eq(prox.syncjob(job), 40)
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_axon_cluster(self): self.thisHostMustNot(platform='windows') busurl = 'local://%s/axons' % guid() dmon = s_daemon.Daemon() dmon.listen(busurl) dmon.share('axons', s_service.SvcBus(), fini=True) with self.getTestDir() as datadir: dir0 = gendir(datadir,'host0') dir1 = gendir(datadir,'host1') dir2 = gendir(datadir,'host2') opts = { 'axonbus':busurl, } host0 = s_axon.AxonHost(dir0,hostname='host0',**opts) host1 = s_axon.AxonHost(dir1,hostname='host1',**opts) host2 = s_axon.AxonHost(dir2,hostname='host2',**opts) props = { 'clones':2, 'syncmax':s_axon.megabyte, 'bytemax':s_axon.megabyte, } axfo0 = host0.add(**props) axon0 = s_telepath.openlink( axfo0[1].get('link') ) # wait for clones to come online self.assertTrue( axon0._waitClonesReady(timeout=2) ) #self.assertIsNotNone( usage.get('total') ) #axon = host.axons.get(iden) iden = axon0.alloc(100) blob = axon0.chunk(iden,b'V'*100) self.assertIsNotNone(blob) self.assertTrue( axon0.has( 'md5', blob[1].get('hash:md5') ) ) self.assertTrue( axon0.has( 'sha1', blob[1].get('hash:sha1') ) ) self.assertTrue( axon0.has( 'sha256', blob[1].get('hash:sha256') ) ) axon0.fini() host0.fini() host1.fini() host2.fini() dmon.fini()
def test_axon_clone_large(self): self.skipLongTest() self.thisHostMustNot(platform='windows') busurl = 'local://%s/axons' % guid() dmon = s_daemon.Daemon() dmon.listen(busurl) dmon.share('axons', s_service.SvcBus(), fini=True) with self.getTestDir() as datadir: dir0 = gendir(datadir, 'host0') dir1 = gendir(datadir, 'host1') dir2 = gendir(datadir, 'host2') dir3 = gendir(datadir, 'host3') host0 = s_axon.AxonHost(dir0, **{'axon:hostname': 'host0', 'axon:axonbus': busurl, 'axon:clones': 1, 'axonhost:autorun': 2, 'axon:bytemax': s_axon.megabyte * 100, }) host1 = s_axon.AxonHost(dir1, **{'axon:hostname': 'host1', 'axon:axonbus': busurl, 'axon:clones': 1, 'axonhost:autorun': 2, 'axon:bytemax': s_axon.megabyte * 100, }) host2 = s_axon.AxonHost(dir2, **{'axon:hostname': 'host2', 'axon:axonbus': busurl, 'axon:clones': 1, 'axonhost:autorun': 2, 'axon:bytemax': s_axon.megabyte * 100, }) host3 = s_axon.AxonHost(dir3, **{'axon:hostname': 'host3', 'axon:axonbus': busurl, 'axon:clones': 1, 'axonhost:autorun': 2, 'axon:bytemax': s_axon.megabyte * 100, }) time.sleep(3) ta = [len(host.axons) for host in [host0, host1, host2, host3]] tc = [len(host.cloneaxons) for host in [host0, host1, host2, host3]] total_axons = sum(ta) total_clones = sum(tc) self.eq(total_axons, 16) self.eq(total_clones, 8) host0.fini() host1.fini() host2.fini() host3.fini() dmon.fini()
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 = collections.defaultdict(int) def count(name): def onmesg(mesg): counters[name] += 1 return onmesg proxy0.on('foo:bar', count('p0')) proxy1.on('foo:bar', count('p1')) func = count('f0') proxy1.on('foo:bar', func, tag='hehe') wait = proxy1.waiter(1, 'foo:bar') proxy0.fire('foo:bar', tag='tagu', tufo=('iden', {'prop': 'valu'})) self.nn(wait.wait(timeout=2)) self.eq(counters['p0'], 1) self.eq(counters['p1'], 1) self.eq(counters['f0'], 0) wait = proxy1.waiter(1, 'foo:bar') proxy0.fire('foo:bar', tag='hehe', tufo=('iden', {'prop': 'valu'})) self.nn(wait.wait(timeout=2)) self.eq(counters['p0'], 2) self.eq(counters['p1'], 2) self.eq(counters['f0'], 1) proxy1.off('foo:bar', func) wait = proxy1.waiter(1, 'foo:bar') proxy0.fire('foo:bar', tag='hehe', tufo=('iden', {'prop': 'valu'})) self.nn(wait.wait(timeout=2)) self.eq(counters['p0'], 3) self.eq(counters['p1'], 3) self.eq(counters['f0'], 1) proxy0.fini() proxy1.fini()
def getSwarmEnv(self): tenv = TstEnv() core0 = s_cortex.openurl('ram://') core1 = s_cortex.openurl('ram://') self.addTstForms(core0) self.addTstForms(core1) tenv.add('core0', core0, fini=True) tenv.add('core1', core1, fini=True) tufo0 = core0.formTufoByProp('strform', 'baz', foo='visi') tufo1 = core0.formTufoByProp('strform', 'faz', foo='visi') tufo2 = core1.formTufoByProp('strform', 'lol', foo='visi') tufo3 = core1.formTufoByProp('strform', 'hai', foo='visi') tufo4 = core0.formTufoByProp('intform', 10, foo='visi') tufo5 = core1.formTufoByProp('intform', 12, foo='romp') tenv.add('tufo0', tufo0) tenv.add('tufo1', tufo1) tenv.add('tufo2', tufo2) tenv.add('tufo3', tufo3) dmon = s_daemon.Daemon() link = dmon.listen('tcp://127.0.0.1:0') tenv.add('link', link) tenv.add('dmon', dmon, fini=True) port = link[1].get('port') svcbus = s_service.SvcBus() tenv.add('svcbus', svcbus, fini=True) dmon.share('syn.svcbus', svcbus) svcrmi = s_telepath.openurl('tcp://127.0.0.1/syn.svcbus', port=port) tenv.add('svcrmi', svcrmi, fini=True) s_service.runSynSvc('cortex', core0, svcrmi, tags=('hehe.haha', )) s_service.runSynSvc('cortex', core1, svcrmi, tags=('hehe.hoho', )) runt = s_runtime.Runtime(svcrmi) tenv.add('runt', runt, fini=True) return tenv
def test_service_proxy(self): with s_daemon.Daemon() as dmon: sbus = s_service.SvcBus() dmon.share('syn.svcbus', sbus, fini=True) link = dmon.listen('tcp://127.0.0.1:0/') port = link[1].get('port') with s_telepath.openurl('tcp://127.0.0.1/syn.svcbus', port=port) as prox: woot0 = Woot() woot1 = Woot() s_service.runSynSvc('woots.woot0', woot0, prox) s_service.runSynSvc('woots.woot1', woot1, prox, tags=('foo.bar', )) svcp = s_service.SvcProxy(prox) foos = svcp.getTagProxy('foo') woots = svcp.getTagProxy('woots') vals = tuple(sorted(foos.foo(20, y=20))) self.eq(vals, (40, )) vals = tuple(sorted(woots.foo(10, y=20))) self.eq(vals, (30, 30)) def runNewpMeth(): for foo in woots.newp(44, y=33): pass self.eq(2, len(svcp.getSynSvcs())) self.eq(2, len(svcp.getSynSvcsByTag('woots'))) woots = svcp.getTagProxy( 'class.synapse.tests.test_lib_service.Woot') vals = tuple(sorted(woots.foo(10, y=20))) self.eq(vals, (30, 30))
def test_service_byname(self): sbus = s_service.SvcBus() woot0 = Woot() with s_daemon.Daemon() as dmon: dmon.share('syn.svcbus', sbus, fini=True) link = dmon.listen('tcp://127.0.0.1:0/') port = link[1].get('port') with s_service.openurl('tcp://127.0.0.1/syn.svcbus', port=port) as prox: iden = prox.runSynSvc('foo0', woot0) self.eq(prox.callByName('foo0', gentask('foo', 20)), 30)
def test_service_byname(self): sbus = s_service.SvcBus() woot0 = Woot() dmon = s_daemon.Daemon() dmon.share('syn.svcbus', sbus, fini=True) link = dmon.listen('tcp://127.0.0.1:0/') port = link[1].get('port') prox = s_service.openurl('tcp://127.0.0.1/syn.svcbus', port=port) iden = prox.runSynSvc('foo0', woot0) self.assertEqual( prox.callByName('foo0', 'foo',20), 30 ) dmon.fini()
def test_service_getTagProxy(self): woot0 = Woot() with s_daemon.Daemon() as dmon: sbus = s_service.SvcBus() dmon.share('syn.svcbus', sbus, fini=True) link = dmon.listen('tcp://127.0.0.1:0/') port = link[1].get('port') with s_service.openurl('tcp://127.0.0.1/syn.svcbus', port=port) as prox: prox.runSynSvc('foo0', woot0, tags=['bar0']) tagprox = prox.getTagProxy('bar0') self.eq(next(tagprox.foo(20), None), 30)
def test_service_getNameProxy(self): woot0 = Woot() with s_daemon.Daemon() as dmon: sbus = s_service.SvcBus() dmon.share('syn.svcbus', sbus, fini=True) link = dmon.listen('tcp://127.0.0.1:0/') port = link[1].get('port') with s_service.openurl('tcp://127.0.0.1/syn.svcbus', port=port) as prox: prox.runSynSvc('foo0', woot0) nameprox = prox.getNameProxy('foo0') self.assertEqual(nameprox.foo(20), 30)
def test_service_proxysugar(self): sbus = s_service.SvcBus() woot0 = Woot() dmon = s_daemon.Daemon() dmon.share('syn.svcbus', sbus, fini=True) link = dmon.listen('tcp://127.0.0.1:0/') port = link[1].get('port') prox = s_service.openurl('tcp://127.0.0.1/syn.svcbus', port=port) iden = prox.runSynSvc('foo0', woot0, tags=('hehe.haha',)) res = list( prox['foo0'].foo(90) ) self.assertEqual( len(res), 1 ) self.assertEqual( res[0], 100 ) dmon.fini()
def test_axon_cluster(self): self.thisHostMustNot(platform='windows') busurl = 'local://%s/axons' % guid() dmon = s_daemon.Daemon() dmon.listen(busurl) dmon.share('axons', s_service.SvcBus(), fini=True) svcprox = s_service.openurl(busurl) axcluster = s_axon.AxonCluster(svcprox) with self.getTestDir() as datadir: dir0 = gendir(datadir, 'host0') dir1 = gendir(datadir, 'host1') dir2 = gendir(datadir, 'host2') opts = { 'axonbus': busurl, } host0 = s_axon.AxonHost(dir0, hostname='host0', **opts) host1 = s_axon.AxonHost(dir1, hostname='host1', **opts) host2 = s_axon.AxonHost(dir2, hostname='host2', **opts) props = { 'clones': 1, 'syncmax': s_axon.megabyte, 'bytemax': s_axon.megabyte, } axfo0 = host0.add(**props) self.assertFalse(axcluster.has('md5', craphash)) self.assertFalse(axcluster.has('md5', asdfhash)) buf = b'asdfasdf' iden = axcluster.alloc(len(buf)) self.assertIsNotNone(axcluster.chunk(iden, buf)) self.assertFalse(axcluster.has('md5', craphash)) self.assertTrue(axcluster.has('md5', asdfhash)) blobs = axcluster.find('md5', craphash) self.assertEqual(len(blobs), 0) blobs = axcluster.find('md5', asdfhash) self.assertEqual(len(blobs), 1) blob = blobs[0] byts = b''.join(axcluster.iterblob(blob)) self.assertEqual(byts, buf) blob[1].pop('.axon') byts = b''.join(axcluster.iterblob(blob)) self.assertEqual(byts, buf) self.assertIsNone(axcluster.wants('md5', asdfhash, len(buf))) self.assertIsNotNone(axcluster.wants('md5', craphash, len(buf))) host0.fini() host1.fini() host2.fini() dmon.fini()
def test_axon_cluster_cortex(self): self.skipLongTest() self.thisHostMustNot(platform='windows') localguid = guid() busurl = 'local://%s/axons' % localguid hahaurl = 'local://%s/haha' % localguid dmon = s_daemon.Daemon() dmon.listen(busurl) dmon.share('axons', s_service.SvcBus(), fini=True) dmon.share('haha', {}) svcprox = s_service.openurl(busurl) axcluster = s_axon.AxonCluster(svcprox) with self.getTestDir() as datadir: dir0 = gendir(datadir, 'host0') dir1 = gendir(datadir, 'host1') dir2 = gendir(datadir, 'host2') host0 = s_axon.AxonHost(dir0, **{'axon:hostname': 'host0', 'axon:axonbus': busurl, 'axon:bytemax': s_axon.megabyte * 100, }) host1 = s_axon.AxonHost(dir1, **{'axon:hostname': 'host1', 'axon:axonbus': busurl, 'axon:bytemax': s_axon.megabyte * 100, }) host2 = s_axon.AxonHost(dir2, **{'axon:hostname': 'host2', 'axon:axonbus': busurl, 'axon:bytemax': s_axon.megabyte * 100, }) props = { 'axon:clones': 1, 'axon:bytemax': s_axon.megabyte, } axfo0 = host0.add(**props) axcluster._waitWrAxons(1, 4) # Ensure our axfo0 was cloned to someone in the cluster axon0 = s_telepath.openlink(axfo0[1].get('link')) # type: s_axon.Axon axon0._waitClonesReady(timeout=16) foundclone = False if host1.cloneaxons: foundclone = True if host2.cloneaxons: foundclone = True self.true(foundclone) axon0.fini() # fini the proxy object core = s_cortex.openurl('ram://') core.setConfOpt('axon:url', busurl) self.false(axcluster.has('md5', craphash)) self.false(axcluster.has('md5', asdfhash)) node = core.formNodeByBytes(b'asdfasdf', name='asdf') self.eq(node[1].get('file:bytes'), asdfhash_iden) self.eq(node[1].get('file:bytes:md5'), asdfhash) self.true(axcluster.has('md5', asdfhash)) self.true(axcluster.has('guid', asdfhash_iden)) fd = io.BytesIO(b'visi') node = core.formNodeByFd(fd, name='visi.bin') self.eq(node[1].get('file:bytes:size'), 4) self.eq(node[1].get('file:bytes:name'), 'visi.bin') self.eq(node[1].get('file:bytes'), '442f602ecf8230b2a59a44b4f845be27') self.eq(node[1].get('file:bytes:md5'), '1b2e93225959e3722efed95e1731b764') self.true(axcluster.has('md5', '1b2e93225959e3722efed95e1731b764')) self.true(axcluster.has('guid', '442f602ecf8230b2a59a44b4f845be27')) host0.fini() host1.fini() host2.fini() svcprox.fini() dmon.fini()
def test_axon_cluster(self): self.skipLongTest() self.thisHostMustNot(platform='windows') busurl = 'local://%s/axons' % guid() dmon = s_daemon.Daemon() dmon.listen(busurl) dmon.share('axons', s_service.SvcBus(), fini=True) svcprox = s_service.openurl(busurl) axcluster = s_axon.AxonCluster(svcprox) with self.getTestDir() as datadir: dir0 = gendir(datadir, 'host0') dir1 = gendir(datadir, 'host1') dir2 = gendir(datadir, 'host2') host0 = s_axon.AxonHost(dir0, **{'axon:hostname': 'host0', 'axon:axonbus': busurl, 'axon:bytemax': s_axon.megabyte * 100, }) host1 = s_axon.AxonHost(dir1, **{'axon:hostname': 'host1', 'axon:axonbus': busurl, 'axon:bytemax': s_axon.megabyte * 100, }) host2 = s_axon.AxonHost(dir2, **{'axon:hostname': 'host2', 'axon:axonbus': busurl, 'axon:bytemax': s_axon.megabyte * 100, }) props = { 'axon:clones': 1, 'axon:bytemax': s_axon.megabyte, } axfo0 = host0.add(**props) axcluster._waitWrAxons(1, 4) # Ensure our axfo0 was cloned to someone in the cluster axon0 = s_telepath.openlink(axfo0[1].get('link')) # type: s_axon.Axon axon0._waitClonesReady(timeout=16) foundclone = False if host1.cloneaxons: foundclone = True if host2.cloneaxons: foundclone = True self.true(foundclone) axon0.fini() # fini the proxy object self.false(axcluster.has('md5', craphash)) self.false(axcluster.has('md5', asdfhash)) buf = b'asdfasdf' iden = axcluster.alloc(len(buf)) self.nn(axcluster.chunk(iden, buf)) self.false(axcluster.has('md5', craphash)) self.true(axcluster.has('md5', asdfhash)) self.true(axcluster.has('guid', asdfhash_iden)) blobs = axcluster.find('md5', craphash) self.eq(len(blobs), 0) time.sleep(0.2) # Yield to axon threads blobs = axcluster.find('md5', asdfhash) # We have two blobs for the same hash since the clone of axfo0 is up on host1/host2 self.eq(len(blobs), 2) blob = blobs[0] byts = b''.join(axcluster.iterblob(blob)) self.eq(byts, buf) blob[1].pop('.axon') byts = b''.join(axcluster.iterblob(blob)) self.eq(byts, buf) self.nn(axcluster.wants('md5', craphash, len(buf))) self.none(axcluster.wants('md5', asdfhash, len(buf))) # Eat bytes via AxonMixin APIs byts = 'pennywise'.encode() blob = axcluster.eatbytes(byts) self.nn(blob) self.isin('.new', blob[1]) blob = axcluster.eatbytes(byts) self.notin('.new', blob[1]) buf = io.BytesIO('dancing clown'.encode()) blob = axcluster.eatfd(buf) self.nn(blob) self.isin('.new', blob[1]) blob = axcluster.eatfd(buf) self.notin('.new', blob[1]) host0.fini() host1.fini() host2.fini() svcprox.fini() dmon.fini()
def test_axon_host_clone(self): self.skipLongTest() self.thisHostMustNot(platform='windows') busurl = 'local://%s/axons' % guid() dmon = s_daemon.Daemon() dmon.listen(busurl) dmon.share('axons', s_service.SvcBus(), fini=True) with self.getTestDir() as datadir: dir0 = gendir(datadir, 'host0') dir1 = gendir(datadir, 'host1') dir2 = gendir(datadir, 'host2') host0 = s_axon.AxonHost(dir0, **{'axon:hostname': 'host0', 'axon:axonbus': busurl, 'axon:bytemax': s_axon.megabyte * 100, }) host1 = s_axon.AxonHost(dir1, **{'axon:hostname': 'host1', 'axon:axonbus': busurl, 'axon:bytemax': s_axon.megabyte * 100, }) host2 = s_axon.AxonHost(dir2, **{'axon:hostname': 'host2', 'axon:axonbus': busurl, 'axon:bytemax': s_axon.megabyte * 100, }) props = { 'axon:bytemax': s_axon.megabyte * 50, } axfo0 = host0.add(**props) axon0 = s_telepath.openlink(axfo0[1].get('link')) # type: s_axon.Axon self.true(axon0._waitClonesReady(timeout=16)) self.notin(axfo0[0], host0.cloneaxons) # get refs to axon0's clones ciden1 = host1.cloneaxons[0] axonc1 = host1.axons.get(ciden1) # type: s_axon.Axon self.eq(axonc1.getConfOpt('axon:clone:iden'), axfo0[0]) ciden2 = host2.cloneaxons[0] axonc2 = host2.axons.get(ciden2) # type: s_axon.Axon self.eq(axonc2.getConfOpt('axon:clone:iden'), axfo0[0]) # Ensure axon:clone events have fired on the cores iden = axon0.alloc(100) cv = b'V' * 100 blob = axon0.chunk(iden, cv) # We need to check the clones of axon0 to ensure that the clones have the data too time.sleep(1) self.nn(blob) self.true(axon0.has('md5', blob[1].get('axon:blob:md5'))) self.true(axon0.has('sha1', blob[1].get('axon:blob:sha1'))) self.true(axon0.has('sha256', blob[1].get('axon:blob:sha256'))) axonbyts = b''.join(_byts for _byts in axon0.iterblob(blob)) self.eq(axonbyts, cv) self.true(axonc1.has('md5', blob[1].get('axon:blob:md5'))) self.true(axonc1.has('sha1', blob[1].get('axon:blob:sha1'))) self.true(axonc1.has('sha256', blob[1].get('axon:blob:sha256'))) axonbyts = b''.join(_byts for _byts in axonc1.iterblob(blob)) self.eq(axonbyts, cv) self.true(axonc2.has('md5', blob[1].get('axon:blob:md5'))) self.true(axonc2.has('sha1', blob[1].get('axon:blob:sha1'))) self.true(axonc2.has('sha256', blob[1].get('axon:blob:sha256'))) axonbyts = b''.join(_byts for _byts in axonc2.iterblob(blob)) self.eq(axonbyts, cv) # Now write a large amount of data to axon0 and ensure that data is replicated blobs = [] n = 5 tststr = 'deadb33f' * 100000 for i in range(n): byts = tststr + 'lol' * i byts = byts.encode() blob = axon0.eatbytes(byts) blobs.append(blob) self.eq(len(blobs), n) time.sleep(2) for i, blob in enumerate(blobs): form, pprop = s_tufo.ndef(blob) ret = axonc1.byiden(pprop) self.nn(ret) ret = axonc2.byiden(pprop) self.nn(ret) # Add axons to the other two hosts and see that they clone over to the other hosts axfo1 = host1.add(**props) axon1 = s_telepath.openlink(axfo1[1].get('link')) # type: s_axon.Axon self.true(axon1._waitClonesReady(timeout=16)) axfo2 = host2.add(**props) axon2 = s_telepath.openlink(axfo2[1].get('link')) # type: s_axon.Axon self.true(axon2._waitClonesReady(timeout=16)) self.eq(len(host0.axons), 3) self.eq(len(host1.axons), 3) self.eq(len(host2.axons), 3) self.eq(len(host0.cloneaxons), 2) self.eq(len(host1.cloneaxons), 2) self.eq(len(host2.cloneaxons), 2) # Fini the proxy objects axonc1.fini() axonc2.fini() axon0.fini() axon1.fini() axon2.fini() # Fini the hosts host0.fini() host1.fini() host2.fini() # Ensure the axonhost fini'd its objects self.true(host0.axonbus.isfini) for axon in host0.axons.values(): self.true(axon.isfini) dmon.fini()
def test_service_proxy_bounce(self): with s_daemon.Daemon() as dmon: sbus = s_service.SvcBus() dmon.share('syn.svcbus', sbus, fini=True) link = dmon.listen('tcp://127.0.0.1:0/') port = link[1].get('port') sprox0 = s_service.SvcProxy(s_telepath.openurl('tcp://127.0.0.1/syn.svcbus', port=port)) sprox1 = s_service.SvcProxy(s_telepath.openurl('tcp://127.0.0.1/syn.svcbus', port=port)) woot0 = Woot() woot1 = Woot() w0 = sprox0.waiter(2, 'syn:svc:init') w1 = sprox0.waiter(2, 'syn:svc:init') sprox0.runSynSvc('woots.woot0', woot0, tags=('foo.bar',)) sprox1.runSynSvc('woots.woot1', woot1, tags=('foo.bar',)) w0.wait(1) w1.wait(1) # Both SvcProxy objects know about both objects and they are not None r = sprox0.getSynSvcsByTag('foo.bar') self.len(2, r) for svcfo in r: self.nn(svcfo) r = sprox1.getSynSvcsByTag('foo.bar') self.len(2, r) for svcfo in r: self.nn(svcfo) r = [_r for _r in sprox0.callByTag('foo.bar', gentask('foo', 1))] self.len(2, r) for svcfo, result in r: self.eq(result, 11) # Tear down sprox1 - it will fini the woots.woot1 service w0 = sprox0.waiter(1, 'syn:svc:fini') sprox1.fini() w0.wait(1) r = sprox0.getSynSvcsByTag('foo.bar') self.len(1, r) for svcfo in r: self.nn(svcfo) # woots.woot0 is still around r = sprox0.callByName('woots.woot0', gentask('foo', 1)) self.eq(r, 11) # Poor woots.woot1 is gone though self.raises(NoSuchObj, sprox0.callByName, 'woots.woot1', gentask('foo', 1)) r = [_r for _r in sprox0.callByTag('foo.bar', gentask('foo', 1))] self.len(1, r) for svcfo, result in r: self.eq(result, 11) # We can recreate sprox1, reshare woot1 and use it sprox1 = s_service.SvcProxy(s_telepath.openurl('tcp://127.0.0.1/syn.svcbus', port=port)) w0 = sprox0.waiter(1, 'syn:svc:init') w1 = sprox1.waiter(1, 'syn:svc:init') sprox1.runSynSvc('woots.woot1', woot1, tags=('foo.bar',)) w0.wait(1) w1.wait(1) # Both SvcProxy objects know about both objects r = sprox0.getSynSvcsByTag('foo.bar') self.len(2, r) for svcfo in r: self.nn(svcfo) r = sprox1.getSynSvcsByTag('foo.bar') self.len(2, r) for svcfo in r: self.nn(svcfo) # We can call woots1 from sprox0 again and by name r = sprox0.callByName('woots.woot1', gentask('foo', 1)) self.eq(r, 11) sprox0.fini() sprox1.fini()