def pantsd_test_context(self, log_level='info', extra_config=None, expected_runs=1): with no_lingering_process_by_command('pantsd-runner'): 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('\npantsd log is {}/pantsd/pantsd.log'.format(workdir)) pantsd_config = { 'GLOBAL': { 'enable_pantsd': True, # 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': '/tmp/watchman.{}.sock'.format(os.getpid()), 'level': log_level, 'pants_subprocessdir': pid_dir, } } if extra_config: recursively_update(pantsd_config, extra_config) print('>>> config: \n{}\n'.format(pantsd_config)) checker = PantsDaemonMonitor(pid_dir) self.assert_success_runner(workdir, pantsd_config, ['kill-pantsd']) try: yield workdir, pantsd_config, checker finally: banner('BEGIN pantsd.log') for line in read_pantsd_log(workdir): print(line) banner('END pantsd.log') self.assert_success_runner( workdir, pantsd_config, ['kill-pantsd'], expected_runs=expected_runs, ) checker.assert_stopped()
def pantsd_test_context(self, log_level='info'): with no_lingering_process_by_command('pantsd-runner'): 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('\npantsd log is {}/pantsd/pantsd.log'.format(workdir)) pantsd_config = { 'GLOBAL': { 'enable_pantsd': True, # 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': '/tmp/watchman.{}.sock'.format(os.getpid()), 'level': log_level, 'pants_subprocessdir': pid_dir } } checker = PantsDaemonMonitor(pid_dir) self.assert_success_runner(workdir, pantsd_config, ['kill-pantsd']) try: yield workdir, pantsd_config, checker finally: banner('BEGIN pantsd.log') for line in read_pantsd_log(workdir): print(line) banner('END pantsd.log') self.assert_success_runner(workdir, pantsd_config, ['kill-pantsd']) checker.assert_stopped()
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-runner'): 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_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-runner'): with self.pantsd_successful_run_context('debug') as (pantsd_run, checker, _): pantsd_run(cmd) checker.await_pantsd() 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 pantsd_test_context(self, log_level='info', extra_config=None, expected_runs=1): with no_lingering_process_by_command( 'pantsd-runner') 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('\npantsd log is {}/pantsd/pantsd.log'.format(workdir)) pantsd_config = { 'GLOBAL': { 'enable_pantsd': True, # 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': '/tmp/watchman.{}.sock'.format(os.getpid()), 'level': log_level, 'pants_subprocessdir': pid_dir, } } if extra_config: recursively_update(pantsd_config, extra_config) print('>>> config: \n{}\n'.format(pantsd_config)) checker = PantsDaemonMonitor(runner_process_context, pid_dir) # TODO(#6574): this should be 1, but when we kill pantsd with a signal it doesn't make sure # to close the run tracker -- we can easily address this by moving that cleanup into the # Exiter. self.assert_runner(workdir, pantsd_config, ['kill-pantsd'], expected_runs=1) try: yield workdir, pantsd_config, checker finally: banner('BEGIN pantsd.log') for line in read_pantsd_log(workdir): print(line) banner('END pantsd.log') self.assert_runner( workdir, pantsd_config, ['kill-pantsd'], # TODO(#6574): this should be 1, see above. expected_runs=1, ) checker.assert_stopped()
def test_pantsd_pantsd_runner_doesnt_die_after_failed_run(self): # Check for no stray pantsd-runner prcesses. with no_lingering_process_by_command('pantsd-runner'): 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-runner prcesses. with no_lingering_process_by_command('pantsd-runner'): 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.await_pantsd() # 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='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('\npantsd log is {}/pantsd/pantsd.log'.format(workdir)) 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': '/tmp/watchman.{}.sock'.format(os.getpid()), 'level': log_level, 'pants_subprocessdir': pid_dir, } } if extra_config: recursively_update(pantsd_config, extra_config) print('>>> config: \n{}\n'.format(pantsd_config)) 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')