def test_register_daemon_manual_terminate_thread(self): conf = self.get_base_config() conf.daemon = TestCounterDaemon conf_string = conf.dumps() counter = pyro.PyroDaemonProcess("test.counter", conf_string=conf_string, conf_sub_path=["daemon"]) counter.start() expected_counts = 127 try: services = pyro.PyroServices() counter_proxy = services.daemon("test.counter", 3) for _ in range(expected_counts): counter_proxy.notify() count = counter_proxy.get_notify_count() self.assertEqual(count, expected_counts) counter_proxy.terminate() is_terminated = counter_proxy.is_terminated() self.assertTrue(is_terminated) self.assertTrue(counter.is_alive()) finally: try: counter.terminate() counter.join() except: pass
def test_wait_for_daemon_too_late(self): conf = self.get_base_config() conf.daemon = TestCounterDaemon conf_string = conf.dumps() counter = pyro.PyroDaemonProcess("test.counter", conf_string=conf_string, conf_sub_path=["daemon"]) start_thread = threading.Timer(15, counter.start) try: services = pyro.PyroServices() start_thread.start() with self.assertRaises(Exception) as context: counter_proxy = services.daemon("test.counter", 10) finally: try: start_thread.cancel() start_thread.join() except: pass try: counter.terminate() counter.join() except: pass
def test_wait_for_daemon_success(self): conf = self.get_base_config() conf.daemon = TestCounterDaemon conf_string = conf.dumps() counter = pyro.PyroDaemonProcess("test.counter", conf_string=conf_string, conf_sub_path=["daemon"]) start_thread = threading.Timer(5, counter.start) try: services = pyro.PyroServices() start_thread.start() counter_proxy = services.daemon("test.counter", 10) counter_proxy.notify() count = counter_proxy.get_notify_count() self.assertEqual(count, 1) finally: try: start_thread.cancel() start_thread.join() except: pass try: counter.terminate() counter.join() except: pass
def test_daemon_process_conf(self): conf = self.get_base_config() conf.daemon = TestCounterDaemon counter = pyro.PyroDaemonProcess("test.counter", conf.daemon) counter.start() expected_counts = 127 try: services = pyro.PyroServices() counter_proxy = services.daemon("test.counter", 3) for _ in range(expected_counts): counter_proxy.notify() count = counter_proxy.get_notify_count() self.assertEqual(count, expected_counts) finally: try: counter.terminate() counter.join() except: pass