Example #1
0
class TestHelloService(IonIntegrationTestCase):
    def setUp(self):
        self._start_container()
        self.container.start_rel_from_url('res/deploy/examples/hello.yml')
        self.hsc = HelloServiceClient()

    def test_hello(self):

        ret = self.hsc.hello("emm")
        self.assertEquals(ret, "BACK:emm")
class TestHelloService(IonIntegrationTestCase):
    def setUp(self):
        self._start_container()
        self.container.start_rel_from_url('res/deploy/examples/hello.yml')
        self.hsc = HelloServiceClient()

    def test_hello(self):

        ret = self.hsc.hello("emm")
        self.assertEquals(ret, "BACK:emm")
    def test_procs(self):
        # Start procs
        config = {}
        pid1 = self.container.spawn_process("hello1",
                                            __name__,
                                            "CoordinatedProcess",
                                            config=config)
        pid2 = self.container.spawn_process("hello2",
                                            __name__,
                                            "CoordinatedProcess",
                                            config=config)
        pid3 = self.container.spawn_process("hello3",
                                            __name__,
                                            "CoordinatedProcess",
                                            config=config)

        # Wait for them to be ready
        gevent.sleep(0.3)

        # Call service
        evt_pub = EventPublisher(event_type=OT.ResourceCommandEvent)
        hc = HelloServiceClient()
        end_time = get_ion_ts_millis() + 4000
        counter = 0
        while get_ion_ts_millis() < end_time:
            counter += 1
            res = hc.hello("foo")
            evt_pub.publish_event(origin=str(counter))
            gevent.sleep(random.random() * 0.1)

        # Wait for them to be finish
        gevent.sleep(0.3)

        # Wrap up
        self.container.terminate_process(pid1)
        self.container.terminate_process(pid2)
        self.container.terminate_process(pid3)

        evt_count = CoordinatedProcess.evt_count
        log.info("Counters: %s", evt_count)

        self.assertEqual(evt_count["total"], 3 * counter)
        master_evts = evt_count[pid1] + evt_count[pid2] + evt_count[pid3]
        self.assertLessEqual(master_evts, counter)
        if master_evts < counter:
            log.info("Lost %s events - no functioning master",
                     counter - master_evts)
    def test_procs(self):
        # Start procs
        config = {}
        pid1 = self.container.spawn_process("hello1", __name__, "CoordinatedProcess", config=config)
        pid2 = self.container.spawn_process("hello2", __name__, "CoordinatedProcess", config=config)
        pid3 = self.container.spawn_process("hello3", __name__, "CoordinatedProcess", config=config)

        # Wait for them to be ready
        gevent.sleep(0.3)

        # Call service
        evt_pub = EventPublisher(event_type=OT.ResourceCommandEvent)
        hc = HelloServiceClient()
        end_time = get_ion_ts_millis() + 4000
        counter = 0
        while get_ion_ts_millis() < end_time:
            counter += 1
            res = hc.hello("foo")
            evt_pub.publish_event(origin=str(counter))
            gevent.sleep(random.random()*0.1)

        # Wait for them to be finish
        gevent.sleep(0.3)

        # Wrap up
        self.container.terminate_process(pid1)
        self.container.terminate_process(pid2)
        self.container.terminate_process(pid3)

        evt_count = CoordinatedProcess.evt_count
        log.info("Counters: %s", evt_count)

        self.assertEqual(evt_count["total"], 3*counter)
        master_evts = evt_count[pid1] + evt_count[pid2] + evt_count[pid3]
        self.assertLessEqual(master_evts, counter)
        if master_evts < counter:
            log.info("Lost %s events - no functioning master", counter - master_evts)