def test_spawn_child(self): child1 = ProcessDesc(name='echo', module='ion.core.test.test_baseprocess') self.assertEquals(child1.proc_state, 'DEFINED') pid1 = yield self.test_sup.spawn_child(child1) self.assertEquals(child1.proc_state, 'INIT_OK') proc = self._get_procinstance(pid1) self.assertEquals( str(proc.__class__), "<class 'ion.core.test.test_baseprocess.EchoProcess'>") self.assertEquals(pid1, proc.receiver.spawned.id) logging.info('Process 1 spawned and initd correctly') (cont, hdrs, msg) = yield self.test_sup.rpc_send(pid1, 'echo', 'content123') self.assertEquals(cont['value'], 'content123') logging.info('Process 1 responsive correctly') # The following tests the process attaching a second receiver msgName = self.test_sup.get_scoped_name('global', pu.create_guid()) messaging = {'name_type': 'worker', 'args': {'scope': 'global'}} yield Container.configure_messaging(msgName, messaging) extraRec = Receiver(proc.proc_name, msgName) extraRec.handle(proc.receive) extraid = yield spawn(extraRec) logging.info('Created new receiver %s with pid %s' % (msgName, extraid)) (cont, hdrs, msg) = yield self.test_sup.rpc_send(msgName, 'echo', 'content456') self.assertEquals(cont['value'], 'content456') logging.info('Process 1 responsive correctly on second receiver')
def test_spawn_child(self): child1 = ProcessDesc(name='echo', module='ion.core.test.test_baseprocess') self.assertEquals(child1.proc_state,'DEFINED') pid1 = yield self.test_sup.spawn_child(child1) self.assertEquals(child1.proc_state,'INIT_OK') proc = self._get_procinstance(pid1) self.assertEquals(str(proc.__class__),"<class 'ion.core.test.test_baseprocess.EchoProcess'>") self.assertEquals(pid1, proc.receiver.spawned.id) logging.info('Process 1 spawned and initd correctly') (cont,hdrs,msg) = yield self.test_sup.rpc_send(pid1,'echo','content123') self.assertEquals(cont['value'], 'content123') logging.info('Process 1 responsive correctly') # The following tests the process attaching a second receiver msgName = self.test_sup.get_scoped_name('global', pu.create_guid()) messaging = {'name_type':'worker', 'args':{'scope':'global'}} yield Container.configure_messaging(msgName, messaging) extraRec = Receiver(proc.proc_name, msgName) extraRec.handle(proc.receive) extraid = yield spawn(extraRec) logging.info('Created new receiver %s with pid %s' % (msgName, extraid)) (cont,hdrs,msg) = yield self.test_sup.rpc_send(msgName,'echo','content456') self.assertEquals(cont['value'], 'content456') logging.info('Process 1 responsive correctly on second receiver')
def test_message_during_init(self): child2 = ProcessDesc(name='echo', module='ion.core.test.test_baseprocess') pid2 = yield self.test_sup.spawn_child(child2, init=False) proc2 = self._get_procinstance(pid2) proc2.plc_init = proc2.plc_noinit self.assertEquals(proc2.proc_state, 'NEW') msgName = self.test_sup.get_scoped_name('global', pu.create_guid()) messaging = {'name_type': 'worker', 'args': {'scope': 'global'}} yield Container.configure_messaging(msgName, messaging) extraRec = Receiver(proc2.proc_name, msgName) extraRec.handle(proc2.receive) extraid = yield spawn(extraRec) logging.info('Created new receiver %s with pid %s' % (msgName, extraid)) yield self.test_sup.send(pid2, 'init', {}, {'quiet': True}) logging.info('Sent init to process 1') yield pu.asleep(0.5) self.assertEquals(proc2.proc_state, 'INIT') (cont, hdrs, msg) = yield self.test_sup.rpc_send(msgName, 'echo', 'content123') self.assertEquals(cont['value'], 'content123') logging.info('Process 1 responsive correctly after init') yield pu.asleep(2) self.assertEquals(proc2.proc_state, 'ACTIVE') (cont, hdrs, msg) = yield self.test_sup.rpc_send(msgName, 'echo', 'content123') self.assertEquals(cont['value'], 'content123') logging.info('Process 1 responsive correctly after init')
def test_message_during_init(self): child2 = ProcessDesc(name='echo', module='ion.core.test.test_baseprocess') pid2 = yield self.test_sup.spawn_child(child2, init=False) proc2 = self._get_procinstance(pid2) proc2.plc_init = proc2.plc_noinit self.assertEquals(proc2.proc_state, 'NEW') msgName = self.test_sup.get_scoped_name('global', pu.create_guid()) messaging = {'name_type':'worker', 'args':{'scope':'global'}} yield Container.configure_messaging(msgName, messaging) extraRec = Receiver(proc2.proc_name, msgName) extraRec.handle(proc2.receive) extraid = yield spawn(extraRec) logging.info('Created new receiver %s with pid %s' % (msgName, extraid)) yield self.test_sup.send(pid2, 'init',{},{'quiet':True}) logging.info('Sent init to process 1') yield pu.asleep(0.5) self.assertEquals(proc2.proc_state, 'INIT') (cont,hdrs,msg) = yield self.test_sup.rpc_send(msgName,'echo','content123') self.assertEquals(cont['value'], 'content123') logging.info('Process 1 responsive correctly after init') yield pu.asleep(2) self.assertEquals(proc2.proc_state, 'ACTIVE') (cont,hdrs,msg) = yield self.test_sup.rpc_send(msgName,'echo','content123') self.assertEquals(cont['value'], 'content123') logging.info('Process 1 responsive correctly after init')