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)
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)
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 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, )
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)
def killall(everywhere=False): """Kills all nailgun servers launched by pants in the current repo. Returns ``True`` if all nailguns were successfully killed, ``False`` otherwise. :param bool everywhere: ``True`` to kill all nailguns servers launched by pants on this machine """ if not NailgunExecutor.killall: return False else: return NailgunExecutor.killall(everywhere=everywhere)
def killall(logger=None, everywhere=False): """Kills all nailgun servers launched by pants in the current repo. Returns ``True`` if all nailguns were successfully killed, ``False`` otherwise. :param logger: a callable that accepts a message string describing the killed nailgun process :param bool everywhere: ``True`` to kill all nailguns servers launched by pants on this machine """ if not NailgunExecutor.killall: return False else: return NailgunExecutor.killall(logger=logger, everywhere=everywhere)
def killall(everywhere=False): """Kills all nailgun servers launched by pants in the current repo. Returns ``True`` if all nailguns were successfully killed, ``False`` otherwise. :param logger: a callable that accepts a message string describing the killed nailgun process :param bool everywhere: ``True`` to kill all nailguns servers launched by pants on this machine """ if not NailgunExecutor.killall: return False else: return NailgunExecutor.killall(everywhere=everywhere)
def create_java_executor(self): """Create java executor that uses this task's ng daemon, if allowed. Call only in execute() or later. TODO: Enforce this. """ if self.nailgun_is_enabled and self.get_options().ng_daemons: classpath = os.pathsep.join(self.tool_classpath('nailgun-server')) client = NailgunExecutor(self._executor_workdir, classpath, distribution=self._dist) else: client = SubprocessExecutor(self._dist) return client
def create_java_executor(self): """Create java executor that uses this task's ng daemon, if allowed. Call only in execute() or later. TODO: Enforce this. """ if self.context.options.nailgun_daemon: classpath = os.pathsep.join( self.tool_classpath(self._nailgun_bootstrap_key)) client = NailgunExecutor(self._executor_workdir, classpath, distribution=self._dist) else: client = SubprocessExecutor(self._dist) return client
def create_java_executor(self): """Create java executor that uses this task's ng daemon, if allowed. Call only in execute() or later. TODO: Enforce this. """ if self.get_options().use_nailgun: classpath = os.pathsep.join(self.tool_classpath('nailgun-server')) return NailgunExecutor(self._identity, self._executor_workdir, classpath, self.dist, connect_timeout=self.get_options().nailgun_timeout_seconds, connect_attempts=self.get_options().nailgun_connect_attempts) else: return SubprocessExecutor(self.dist)
def create_java_executor(self, dist=None, force_subprocess=False): """Create java executor that uses this task's ng daemon, if allowed. Call only in execute() or later. TODO: Enforce this. """ dist = dist or self.dist if self.execution_strategy == self.ExecutionStrategy.nailgun and not force_subprocess: classpath = os.pathsep.join(self.tool_classpath('nailgun-server')) return NailgunExecutor( self._identity, self._executor_workdir, classpath, dist, startup_timeout=self.get_options( ).nailgun_subprocess_startup_timeout, connect_timeout=self.get_options().nailgun_timeout_seconds, connect_attempts=self.get_options().nailgun_connect_attempts) else: return SubprocessExecutor(dist)
def setUp(self): self.executor = NailgunExecutor(identity='test', workdir='/__non_existent_dir', nailgun_classpath=[], distribution=mock.Mock())