Esempio n. 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()
Esempio n. 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()
Esempio n. 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)
Esempio n. 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)
Esempio n. 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)
Esempio n. 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)
Esempio n. 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})
Esempio n. 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()
Esempio n. 9
0
 def test_terminate(self, kill):
     p = Process(Mock())
     p.pid = 1234
     p.terminate()
     kill.assert_called_once_with(p.pid, 9)
Esempio n. 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)
Esempio n. 11
0
 def test_wait(self, wait):
     p = Process(Mock())
     p.wait()
     wait.assert_called_once_with(p.pid, 0)
Esempio n. 12
0
 def test_terminate_not_forked(self, kill):
     p = Process(Mock())
     p.terminate()
     self.assertFalse(kill.called)
Esempio n. 13
0
 def test_wait(self, wait):
     p = Process(Mock())
     p.wait()
     wait.assert_called_once_with(p.pid, 0)
Esempio n. 14
0
 def test_terminate_not_forked(self, kill):
     p = Process(Mock())
     p.terminate()
     self.assertFalse(kill.called)
Esempio n. 15
0
 def test_terminate(self, kill):
     p = Process(Mock())
     p.pid = 1234
     p.terminate()
     kill.assert_called_once_with(p.pid, 9)
Esempio n. 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)