def pantsd_test_context(
        self,
        *,
        log_level: str = "info",
        extra_config: Optional[Dict[str, Any]] = None
    ) -> Iterator[Tuple[str, Dict[str, Any], PantsDaemonMonitor]]:
        with temporary_dir(root_dir=os.getcwd()) 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": {
                    "pantsd": True,
                    "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(pid_dir)
            kill_daemon(pid_dir)
            try:
                yield (workdir, pantsd_config, checker)
                kill_daemon(pid_dir)
                checker.assert_stopped()
            finally:
                banner("BEGIN pantsd.log")
                for line in read_pantsd_log(workdir):
                    print(line)
                banner("END pantsd.log")
Beispiel #2
0
    def test_pantsd_file_logging(self) -> None:
        with self.pantsd_successful_run_context("debug") as ctx:
            daemon_run = ctx.runner(["list", "3rdparty::"])
            ctx.checker.assert_started()
            assert "[DEBUG] connecting to pantsd on port" in daemon_run.stderr_data

            pantsd_log = "\n".join(read_pantsd_log(ctx.workdir))
            assert "[DEBUG] logging initialized" in pantsd_log
Beispiel #3
0
    def test_pantsd_file_logging(self) -> None:
        with self.pantsd_successful_run_context("debug") as ctx:
            daemon_run = ctx.runner(
                ["--backend-packages=pants.backend.python", "list", "3rdparty::"]
            )
            ctx.checker.assert_started()
            assert "[DEBUG] Connecting to pantsd on port" in daemon_run.stderr

            pantsd_log = "\n".join(read_pantsd_log(ctx.workdir))
            assert "[DEBUG] Logging reinitialized in pantsd context" in pantsd_log
Beispiel #4
0
    def test_sigint_kills_request_waiting_for_lock(self):
        """Test that, when a pailgun request is blocked waiting for another one to end, sending
        SIGINT to the blocked run will kill it.

        Regression test for issue: #7920
        """
        config = {
            "GLOBAL": {
                "pantsd_timeout_when_multiple_invocations": -1,
                "level": "debug"
            }
        }
        with self.pantsd_test_context(extra_config=config) as (workdir, config,
                                                               checker):
            # Run a repl, so that any other run waiting to acquire the daemon lock waits forever.
            first_run_handle = self.run_pants_with_workdir_without_waiting(
                command=["repl", "examples/src/python/example/hello::"],
                workdir=workdir,
                config=config,
            )
            checker.assert_started()
            checker.assert_running()

            blocking_run_handle = self.run_pants_with_workdir_without_waiting(
                command=["goals"], workdir=workdir, config=config)

            # Block until the second request is waiting for the lock.
            blocked = True
            while blocked:
                log = "\n".join(read_pantsd_log(workdir))
                if "didn't acquire the lock on the first try, polling." in log:
                    blocked = False
                # NB: This sleep is totally deterministic, it's just so that we don't spend too many cycles
                # busy waiting.
                time.sleep(0.1)

            # Sends SIGINT to the run that is waiting.
            blocking_run_client_pid = blocking_run_handle.process.pid
            os.kill(blocking_run_client_pid, signal.SIGINT)
            blocking_run_handle.join()

            # Check that pantsd is still serving the other request.
            checker.assert_running()

            # Send exit() to the repl, and exit it.
            result = first_run_handle.join(stdin_data="exit()")
            self.assert_success(result)
            checker.assert_running()
Beispiel #5
0
 def full_pantsd_log():
     return "\n".join(read_pantsd_log(ctx.workdir))