Пример #1
0
    def _launch_waiter(cls, workdir: str, config) -> Tuple[PantsJoinHandle, int, str]:
        """Launch a process via pantsd that will wait forever for the a file to be created.

        Returns the pid of the pantsd client, the pid of the waiting child process, and the file to
        create to cause the waiting child to exit.
        """
        file_to_make = os.path.join(workdir, "some_magic_file")
        waiter_pid_file = os.path.join(workdir, "pid_file")

        argv = [
            "run",
            "testprojects/src/python/coordinated_runs:waiter",
            "--",
            file_to_make,
            waiter_pid_file,
        ]
        client_handle = cls.run_pants_with_workdir_without_waiting(
            argv, workdir=workdir, config=config
        )
        waiter_pid = -1
        for _ in attempts("The waiter process should have written its pid."):
            waiter_pid_str = maybe_read_file(waiter_pid_file)
            if waiter_pid_str:
                waiter_pid = int(waiter_pid_str)
                break
        return client_handle, waiter_pid, file_to_make
def test_ctrl_c() -> None:
    with temporary_workdir() as workdir:
        dest = os.path.join(workdir, "dest.log")

        # Start a pantsd run that will wait forever, then kill the pantsd client.
        client_handle, _, _ = launch_waiter(workdir=workdir, config=workunit_logger_config(dest))
        client_pid = client_handle.process.pid
        os.kill(client_pid, signal.SIGINT)

        # Confirm that finish is still called (even though it may be backgrounded in the server).
        for _ in attempts("The log should eventually show that the SWH shut down."):
            content = maybe_read_file(dest)
            if content and FINISHED_SUCCESSFULLY in content:
                break
def confirm_eventual_success(log_dest: str) -> None:
    for _ in attempts(
            "The log should eventually show that the SWH shut down."):
        content = maybe_read_file(log_dest)
        if content and FINISHED_SUCCESSFULLY in content:
            break