def test_pantsd_stray_runners(self): # Allow env var overrides for local stress testing. attempts = int(os.environ.get("PANTS_TEST_PANTSD_STRESS_ATTEMPTS", 20)) cmd = os.environ.get("PANTS_TEST_PANTSD_STRESS_CMD", "help").split() with no_lingering_process_by_command("pantsd"): with self.pantsd_successful_run_context(log_level="debug") as ctx: ctx.runner(cmd) ctx.checker.assert_started() for _ in range(attempts): ctx.runner(cmd) ctx.checker.assert_running() # The runner can sometimes exit more slowly than the thin client caller. time.sleep(3)
def test_pantsd_stray_runners(self): # Allow env var overrides for local stress testing. attempts = int(os.environ.get('PANTS_TEST_PANTSD_STRESS_ATTEMPTS', 20)) cmd = os.environ.get('PANTS_TEST_PANTSD_STRESS_CMD', 'help').split() with no_lingering_process_by_command('pantsd'): with self.pantsd_successful_run_context('debug') as (pantsd_run, checker, _, _): pantsd_run(cmd) checker.assert_started() for _ in range(attempts): pantsd_run(cmd) checker.assert_running() # The runner can sometimes exit more slowly than the thin client caller. time.sleep(3)
def test_pantsd_pantsd_runner_doesnt_die_after_failed_run(self): # Check for no stray pantsd prcesses. with no_lingering_process_by_command('pantsd'): with self.pantsd_test_context() as (workdir, pantsd_config, checker): # Run target that throws an exception in pants. self.assert_failure( self.run_pants_with_workdir( ['bundle', 'testprojects/src/java/org/pantsbuild/testproject/bundle:missing-files'], workdir, pantsd_config) ) checker.assert_started() # Assert pantsd is in a good functional state. self.assert_success(self.run_pants_with_workdir(['help'], workdir, pantsd_config)) checker.assert_running()
def test_pantsd_pantsd_runner_doesnt_die_after_failed_run(self): # Check for no stray pantsd prcesses. with no_lingering_process_by_command('pantsd'): with self.pantsd_test_context() as (workdir, pantsd_config, checker): # Run target that throws an exception in pants. self.assert_failure( self.run_pants_with_workdir([ 'lint', 'testprojects/src/python/unicode/compilation_failure' ], workdir, pantsd_config)) checker.assert_started() # Assert pantsd is in a good functional state. self.assert_success( self.run_pants_with_workdir(['help'], workdir, pantsd_config)) checker.assert_running()
def pantsd_test_context( self, *, log_level: str = "info", extra_config: Optional[Dict[str, Any]] = None ) -> Iterator[Tuple[str, Dict[str, Any], PantsDaemonMonitor]]: with no_lingering_process_by_command( "pantsd") as runner_process_context: with self.temporary_workdir() as workdir_base: pid_dir = os.path.join(workdir_base, ".pids") workdir = os.path.join(workdir_base, ".workdir.pants.d") print(f"\npantsd log is {workdir}/pantsd/pantsd.log") pantsd_config = { "GLOBAL": { "enable_pantsd": True, "shutdown_pantsd_after_run": False, # The absolute paths in CI can exceed the UNIX socket path limitation # (>104-108 characters), so we override that here with a shorter path. "watchman_socket_path": f"/tmp/watchman.{os.getpid()}.sock", "level": log_level, "pants_subprocessdir": pid_dir, } } if extra_config: recursively_update(pantsd_config, extra_config) print(f">>> config: \n{pantsd_config}\n") checker = PantsDaemonMonitor(runner_process_context, pid_dir) self.assert_runner(workdir, pantsd_config, ["kill-pantsd"]) try: yield workdir, pantsd_config, checker self.assert_runner( workdir, pantsd_config, ["kill-pantsd"], ) checker.assert_stopped() finally: banner("BEGIN pantsd.log") for line in read_pantsd_log(workdir): print(line) banner("END pantsd.log")
def pantsd_test_context(self, log_level='info', extra_config=None): with no_lingering_process_by_command( 'pantsd') as runner_process_context: with self.temporary_workdir() as workdir_base: pid_dir = os.path.join(workdir_base, '.pids') workdir = os.path.join(workdir_base, '.workdir.pants.d') print(f'\npantsd log is {workdir}/pantsd/pantsd.log') pantsd_config = { 'GLOBAL': { 'enable_pantsd': True, 'shutdown_pantsd_after_run': False, # The absolute paths in CI can exceed the UNIX socket path limitation # (>104-108 characters), so we override that here with a shorter path. 'watchman_socket_path': f'/tmp/watchman.{os.getpid()}.sock', 'level': log_level, 'pants_subprocessdir': pid_dir, } } if extra_config: recursively_update(pantsd_config, extra_config) print(f'>>> config: \n{pantsd_config}\n') checker = PantsDaemonMonitor(runner_process_context, pid_dir) self.assert_runner(workdir, pantsd_config, ['kill-pantsd'], expected_runs=1) try: yield workdir, pantsd_config, checker self.assert_runner( workdir, pantsd_config, ['kill-pantsd'], expected_runs=1, ) checker.assert_stopped() finally: banner('BEGIN pantsd.log') for line in read_pantsd_log(workdir): print(line) banner('END pantsd.log')