예제 #1
0
    def test_health_thread(self):
        real_sleep = time.sleep

        def sleep(*args):
            real_sleep(0.1)

        with mock.patch('mi.core.service_registry.time.sleep') as sleep_mock:
            sleep_mock.side_effect = sleep
            thread = ConsulServiceRegistry.create_health_thread(
                self.PA_NAME, self.PA_PORT)
            thread.start()

            self.assertIsInstance(thread, threading.Thread)
            self.assertTrue(thread.is_alive())
            # Sleep just long enough to send a passing check to consul
            sleep()

            thread.running = False
            thread.join()
            self.assertFalse(thread.is_alive())

            # verify we have registered our driver and we are in a passing state
            _, result = CONSUL.health.service(DRIVER_SERVICE_NAME,
                                              tag=self.PA_NAME,
                                              passing=True)
            self.assertEqual(len(result), 1)
예제 #2
0
    def start_threads(self):
        """
        Initialize and start messaging resources for the driver, blocking
        until messaging terminates. This ZMQ implementation starts and
        joins command and event threads, managing nonblocking send/recv calls
        on REP and PUB sockets, respectively. Terminate loops and close
        sockets when stop flag is set in driver process.
        """
        self.event_publisher.start()
        self.particle_publisher.start()

        self.load_balancer = LoadBalancer(self, self.num_workers)
        self.port = self.load_balancer.port

        # now that we have a port, start our status thread
        self.status_thread = ConsulServiceRegistry.create_health_thread(self.refdes, self.port)
        self.status_thread.setDaemon(True)
        self.status_thread.start()

        self.load_balancer.run()
예제 #3
0
    def start_threads(self):
        """
        Initialize and start messaging resources for the driver, blocking
        until messaging terminates. This ZMQ implementation starts and
        joins command and event threads, managing nonblocking send/recv calls
        on REP and PUB sockets, respectively. Terminate loops and close
        sockets when stop flag is set in driver process.
        """
        self.event_publisher.start()
        self.particle_publisher.start()

        self.load_balancer = LoadBalancer(self, self.num_workers)
        self.port = self.load_balancer.port

        # now that we have a port, start our status thread
        self.status_thread = ConsulServiceRegistry.create_health_thread(self.refdes, self.port)
        self.status_thread.setDaemon(True)
        self.status_thread.start()

        self.load_balancer.run()
    def test_health_thread(self):
        real_sleep = time.sleep

        def sleep(*args):
            real_sleep(0.1)

        with mock.patch('mi.core.service_registry.time.sleep') as sleep_mock:
            sleep_mock.side_effect = sleep
            thread = ConsulServiceRegistry.create_health_thread(self.PA_NAME, self.PA_PORT)
            thread.start()

            self.assertIsInstance(thread, threading.Thread)
            self.assertTrue(thread.is_alive())
            # Sleep just long enough to send a passing check to consul
            sleep()

            thread.running = False
            thread.join()
            self.assertFalse(thread.is_alive())

            # verify we have registered our driver and we are in a passing state
            _, result = CONSUL.health.service(DRIVER_SERVICE_NAME, tag=self.PA_NAME, passing=True)
            self.assertEqual(len(result), 1)