def test_000_switchboard_process_construct_destruct(self):
     """Test constructing and destructing raises no errors."""
     self.uut = switchboard_process.SwitchboardProcess(
         "fake_device", "fake_process", self.exception_queue,
         self.command_queue)
     self.assertFalse(self.uut.is_started(),
                      "Expected process not started, found started")
     self.assertFalse(self.uut.is_running(),
                      "Expected process to not running, found running")
 def test_120_switchboard_process_send_command_rejects_invalid_command(
         self):
     """Test send_command rejects invalid command."""
     self.uut = switchboard_process.SwitchboardProcess(
         "fake_device", "fake_command", self.exception_queue,
         self.command_queue)
     # Invalid command
     with self.assertRaisesRegex(ValueError, "is not a valid command in"):
         self.uut.send_command("invalid command")
Exemple #3
0
 def test_switchboard_process(self):
     """Test starting a Switchboard child process."""
     command_queue = multiprocessing_utils.get_context().Queue()
     exception_queue = multiprocessing_utils.get_context().Queue()
     proc = switchboard_process.SwitchboardProcess("some_device",
                                                   "some_process",
                                                   exception_queue,
                                                   command_queue)
     proc.start()
     proc.stop()
 def test_121_switchboard_process_send_message_accepts_valid_command(self):
     """Test send_command accepts a valid command."""
     self.uut = switchboard_process.SwitchboardProcess(
         "fake_device",
         "fake_command",
         self.exception_queue,
         self.command_queue,
         valid_commands=("valid_command", ))
     self.uut.send_command("valid_command", "Data")
     wait_for_queue_writes(self.command_queue)
     self.assertFalse(self.command_queue.empty(),
                      "Expected command queue to not be empty")
 def test_130_switchboard_process_protected_methods_exist(self):
     """Test that switchboard_process private methods exist and work."""
     self.uut = switchboard_process.SwitchboardProcess(
         "fake_device",
         "fake_command",
         self.exception_queue,
         self.command_queue,
         valid_commands=("valid_command", ))
     self.assertFalse(self.uut._do_work(),
                      "Expected _do_work to return False")
     self.assertTrue(self.uut._pre_run_hook(),
                     "Expected _pre_run_hook to return True")
     self.assertIsNone(self.uut._post_run_hook(),
                       "Expected _post_run_hook to return None")
 def test_104_switchboard_process_stop_after_manager_shutdown(self):
     """Test stopping child process after manager shutdown."""
     self.uut = switchboard_process.SwitchboardProcess(
         "fake_device", "fake_process", self.exception_queue,
         self.command_queue)
     self.uut._do_work = do_work_return_true
     self.uut.start()
     self.assertTrue(self.uut.is_running(),
                     "Expected process to end, still running")
     self.assertTrue(self.uut.is_started(),
                     "Expected process started, found not started")
     self.uut.stop()
     self.assertFalse(self.uut.is_started(),
                      "Expected process not started, found started")
 def test_122_switchboard_process_send_command_and_is_command_consumed(
         self):
     """Test send_command and is_command_consumed works."""
     self.uut = switchboard_process.SwitchboardProcess(
         "fake_device",
         "fake_command",
         self.exception_queue,
         self.command_queue,
         valid_commands=("valid_command", ))
     self.assertTrue(self.uut.is_command_consumed())
     self.uut.send_command("valid_command", "Data")
     wait_for_queue_writes(self.command_queue)
     self.assertFalse(self.uut.is_command_consumed())
     self.command_queue.get()
     self.assertTrue(self.uut.is_command_consumed())
 def test_100_switchboard_process_start_stop(self):
     """Test starting and stopping child process that exits immediately."""
     self.uut = switchboard_process.SwitchboardProcess(
         "fake_device", "fake_process", self.exception_queue,
         self.command_queue)
     self.uut.start()
     end_time = time.time() + _EXIT_TIMEOUT
     while self.uut.is_running() and time.time() < end_time:
         time.sleep(0.001)
     self.assertFalse(self.uut.is_running(),
                      "Expected process to end, still running")
     self.assertTrue(self.uut.is_started(),
                     "Expected process started, found not started")
     self.uut.stop()
     self.assertFalse(self.uut.is_started(),
                      "Expected process not started, found started")