示例#1
0
class NailgunExecutorTest(TestBase):
    def setUp(self):
        super(NailgunExecutorTest, self).setUp()
        self.executor = NailgunExecutor(identity='test',
                                        workdir='/__non_existent_dir',
                                        nailgun_classpath=[],
                                        distribution=mock.Mock(),
                                        metadata_base_dir=self.subprocess_dir)

    def test_is_alive_override(self):
        with mock.patch.object(NailgunExecutor, '_as_process',
                               **PATCH_OPTS) as mock_as_process:
            mock_as_process.return_value = fake_process(
                name='java',
                pid=3,
                status=psutil.STATUS_IDLE,
                cmdline=[
                    b'java', b'-arg', NailgunExecutor._PANTS_NG_BUILDROOT_ARG
                ])
            self.assertTrue(self.executor.is_alive())
            mock_as_process.assert_called_with(self.executor)

    def test_is_alive_override_not_my_process(self):
        with mock.patch.object(NailgunExecutor, '_as_process',
                               **PATCH_OPTS) as mock_as_process:
            mock_as_process.return_value = fake_process(
                name='java',
                pid=3,
                status=psutil.STATUS_IDLE,
                cmdline=[b'java', b'-arg', b'-arg2'])
            self.assertFalse(self.executor.is_alive())
            mock_as_process.assert_called_with(self.executor)
class NailgunExecutorTest(TestBase):
  def setUp(self):
    super(NailgunExecutorTest, self).setUp()
    self.executor = NailgunExecutor(identity='test',
                                    workdir='/__non_existent_dir',
                                    nailgun_classpath=[],
                                    distribution=mock.Mock(),
                                    metadata_base_dir=self.subprocess_dir)

  def test_is_alive_override(self):
    with mock.patch.object(NailgunExecutor, '_as_process', **PATCH_OPTS) as mock_as_process:
      mock_as_process.return_value = fake_process(
        name='java',
        pid=3,
        status=psutil.STATUS_IDLE,
        cmdline=['java', '-arg', NailgunExecutor._PANTS_NG_BUILDROOT_ARG]
      )
      self.assertTrue(self.executor.is_alive())
      mock_as_process.assert_called_with(self.executor)

  def test_is_alive_override_not_my_process(self):
    with mock.patch.object(NailgunExecutor, '_as_process', **PATCH_OPTS) as mock_as_process:
      mock_as_process.return_value = fake_process(
        name='java',
        pid=3,
        status=psutil.STATUS_IDLE,
        cmdline=['java', '-arg', '-arg2']
      )
      self.assertFalse(self.executor.is_alive())
      mock_as_process.assert_called_with(self.executor)
示例#3
0
class NailgunExecutorTest(TestBase):
    def setUp(self):
        super().setUp()
        self.executor = NailgunExecutor(
            identity="test",
            workdir="/__non_existent_dir",
            nailgun_classpath=[],
            distribution=unittest.mock.Mock(),
            metadata_base_dir=self.subprocess_dir,
        )

    def test_is_alive_override(self):
        with unittest.mock.patch.object(NailgunExecutor, "_as_process",
                                        **PATCH_OPTS) as mock_as_process:
            mock_as_process.return_value = fake_process(
                name="java",
                pid=3,
                status=psutil.STATUS_IDLE,
                cmdline=[
                    b"java", b"-arg", NailgunExecutor._PANTS_NG_BUILDROOT_ARG
                ],
            )
            self.assertTrue(self.executor.is_alive())
            mock_as_process.assert_called_with(self.executor)

    def test_is_alive_override_not_my_process(self):
        with unittest.mock.patch.object(NailgunExecutor, "_as_process",
                                        **PATCH_OPTS) as mock_as_process:
            mock_as_process.return_value = fake_process(
                name="java",
                pid=3,
                status=psutil.STATUS_IDLE,
                cmdline=[b"java", b"-arg", b"-arg2"])
            self.assertFalse(self.executor.is_alive())
            mock_as_process.assert_called_with(self.executor)

    def test_connect_timeout(self):
        with rw_pipes() as (stdout_read, _), unittest.mock.patch(
                "pants.java.nailgun_executor.safe_open"
        ) as mock_open, unittest.mock.patch(
                "pants.java.nailgun_executor.read_file") as mock_read_file:
            mock_open.return_value = stdout_read
            mock_read_file.return_value = "err"
            # The stdout write pipe has no input and hasn't been closed, so the selector.select() should
            # time out regardless of the timemout argument, and raise.
            with self.assertRaisesWithMessage(
                    NailgunExecutor.InitialNailgunConnectTimedOut,
                    """\
Failed to read nailgun output after 0.0001 seconds!
Stdout:

Stderr:
err""",
            ):
                self.executor._await_socket(timeout=0.0001)
class NailgunExecutorTest(TestBase):
  def setUp(self):
    super(NailgunExecutorTest, self).setUp()
    self.executor = NailgunExecutor(identity='test',
                                    workdir='/__non_existent_dir',
                                    nailgun_classpath=[],
                                    distribution=mock.Mock(),
                                    metadata_base_dir=self.subprocess_dir)

  def test_is_alive_override(self):
    with mock.patch.object(NailgunExecutor, '_as_process', **PATCH_OPTS) as mock_as_process:
      mock_as_process.return_value = fake_process(
        name='java',
        pid=3,
        status=psutil.STATUS_IDLE,
        cmdline=[b'java', b'-arg', NailgunExecutor._PANTS_NG_BUILDROOT_ARG]
      )
      self.assertTrue(self.executor.is_alive())
      mock_as_process.assert_called_with(self.executor)

  def test_is_alive_override_not_my_process(self):
    with mock.patch.object(NailgunExecutor, '_as_process', **PATCH_OPTS) as mock_as_process:
      mock_as_process.return_value = fake_process(
        name='java',
        pid=3,
        status=psutil.STATUS_IDLE,
        cmdline=[b'java', b'-arg', b'-arg2']
      )
      self.assertFalse(self.executor.is_alive())
      mock_as_process.assert_called_with(self.executor)

  def test_connect_timeout(self):
    with rw_pipes() as (stdout_read, _),\
         mock.patch('pants.java.nailgun_executor.safe_open') as mock_open,\
         mock.patch('pants.java.nailgun_executor.read_file') as mock_read_file:
      mock_open.return_value = stdout_read
      mock_read_file.return_value = 'err'
      # The stdout write pipe has no input and hasn't been closed, so the select.select() should
      # time out regardless of the timemout argument, and raise.
      with self.assertRaisesWithMessage(NailgunExecutor.InitialNailgunConnectTimedOut, """\
Failed to read nailgun output after 0.0001 seconds!
Stdout:

Stderr:
err"""):
        self.executor._await_socket(timeout=0.0001)