Beispiel #1
0
    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()
Beispiel #2
0
    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()
Beispiel #3
0
    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)
Beispiel #4
0
    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)
Beispiel #5
0
    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)
Beispiel #6
0
    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)
Beispiel #7
0
    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})
Beispiel #8
0
 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()
Beispiel #9
0
 def test_terminate(self, kill):
     p = Process(Mock())
     p.pid = 1234
     p.terminate()
     kill.assert_called_once_with(p.pid, 9)
Beispiel #10
0
 def test_wait_error(self, wait):
     wait.side_effect = OSError()
     p = Process(Mock())
     p.wait()
     wait.assert_called_once_with(p.pid, 0)
Beispiel #11
0
 def test_wait(self, wait):
     p = Process(Mock())
     p.wait()
     wait.assert_called_once_with(p.pid, 0)
Beispiel #12
0
 def test_terminate_not_forked(self, kill):
     p = Process(Mock())
     p.terminate()
     self.assertFalse(kill.called)
Beispiel #13
0
 def test_wait(self, wait):
     p = Process(Mock())
     p.wait()
     wait.assert_called_once_with(p.pid, 0)
Beispiel #14
0
 def test_terminate_not_forked(self, kill):
     p = Process(Mock())
     p.terminate()
     self.assertFalse(kill.called)
Beispiel #15
0
 def test_terminate(self, kill):
     p = Process(Mock())
     p.pid = 1234
     p.terminate()
     kill.assert_called_once_with(p.pid, 9)
Beispiel #16
0
 def test_wait_error(self, wait):
     wait.side_effect = OSError()
     p = Process(Mock())
     p.wait()
     wait.assert_called_once_with(p.pid, 0)