def test_start_child(self, run, fork): fork.return_value = 0 p = Process(Mock()) # test p.start() # validation fork.assert_called_once_with() run.assert_called_once_with()
def test_run(self): main = Mock() args = (1, 2) kwargs = {'a': 3, 'b': 4} # test p = Process(main, *args, **kwargs) p.run() # validation p.main.assert_called_once_with(*args, **kwargs)
def test_start_parent(self, run, fork): fork.return_value = 1234 p = Process(Mock()) # test p.start() # validation fork.assert_called_once_with() self.assertFalse(run.called) self.assertEqual(p.pid, fork.return_value)
def test_init(self): main = Mock() args = (1, 2) kwargs = {'a': 3, 'b': 4} # test p = Process(main, *args, **kwargs) # validation self.assertEqual(p.main, main) self.assertEqual(p.args, (1, 2)) self.assertEqual(p.kwargs, {'a': 3, 'b': 4})
def __call__(self): """ Invoke the RMI as follows: - Fork - Start the monitor. - Read and dispatch reply messages. :return: Whatever method returned. """ pipe = Pipe() target = Target(self.method, *self.args, **self.kwargs) child = Process(target, pipe) monitor = Monitor(Context.current(), child) try: child.start() monitor.start() pipe.writer.close() retval = self.read(pipe.reader) return retval finally: pipe.close() monitor.stop() child.wait()
def test_terminate(self, kill): p = Process(Mock()) p.pid = 1234 p.terminate() kill.assert_called_once_with(p.pid, 9)
def test_wait_error(self, wait): wait.side_effect = OSError() p = Process(Mock()) p.wait() wait.assert_called_once_with(p.pid, 0)
def test_wait(self, wait): p = Process(Mock()) p.wait() wait.assert_called_once_with(p.pid, 0)
def test_terminate_not_forked(self, kill): p = Process(Mock()) p.terminate() self.assertFalse(kill.called)