示例#1
0
def test_prepare_scheduler():
    # A core with no services.
    def create_services(bootstrap_options, legacy_graph_scheduler):
        return PantsServices()

    core = PantsDaemonCore(create_services)

    first_scheduler = core.prepare_scheduler(create_options_bootstrapper(args=["-ldebug"]))
    second_scheduler = core.prepare_scheduler(create_options_bootstrapper(args=["-lwarn"]))

    assert first_scheduler is not second_scheduler
示例#2
0
def test_prepare_scheduler():
    # A core with no services.
    def create_services(bootstrap_options, legacy_graph_scheduler):
        return PantsServices()

    core = PantsDaemonCore(create_options_bootstrapper([]), PyExecutor(2, 4),
                           create_services)

    first_scheduler, first_options_initializer = core.prepare(
        create_options_bootstrapper(["-ldebug"]))
    second_scheduler, second_options_initializer = core.prepare(
        create_options_bootstrapper(["-lwarn"]))
    assert first_scheduler is not second_scheduler
    assert first_options_initializer is second_options_initializer
示例#3
0
    def create(cls, options_bootstrapper: OptionsBootstrapper,
               env: CompleteEnvironment) -> PantsDaemon:
        # Any warnings that would be triggered here are re-triggered later per-run of Pants, so we
        # silence them.
        with warnings.catch_warnings(record=True):
            bootstrap_options = options_bootstrapper.bootstrap_options
            bootstrap_options_values = bootstrap_options.for_global_scope()

        executor = GlobalOptions.create_py_executor(bootstrap_options_values)
        core = PantsDaemonCore(options_bootstrapper, env, executor,
                               cls._setup_services)

        server = native_engine.nailgun_server_create(
            executor,
            bootstrap_options_values.pantsd_pailgun_port,
            DaemonPantsRunner(core),
        )

        return PantsDaemon(
            work_dir=bootstrap_options_values.pants_workdir,
            log_level=bootstrap_options_values.level,
            server=server,
            core=core,
            metadata_base_dir=bootstrap_options_values.pants_subprocessdir,
            bootstrap_options=bootstrap_options,
        )
示例#4
0
    def create(cls, options_bootstrapper) -> "PantsDaemon":
        """
        :param OptionsBootstrapper options_bootstrapper: The bootstrap options.
        :param bool full_init: Whether or not to fully initialize an engine et al for the purposes
                                of spawning a new daemon. `full_init=False` is intended primarily
                                for lightweight lifecycle checks (since there is a ~1s overhead to
                                initialize the engine). See the impl of `maybe_launch` for an example
                                of the intended usage.
        """
        native = Native()
        native.override_thread_logging_destination_to_just_pantsd()

        bootstrap_options = options_bootstrapper.bootstrap_options
        bootstrap_options_values = bootstrap_options.for_global_scope()

        core = PantsDaemonCore(cls._setup_services)

        server = native.new_nailgun_server(
            bootstrap_options_values.pantsd_pailgun_port,
            DaemonPantsRunner(core),
        )

        return PantsDaemon(
            native=native,
            work_dir=bootstrap_options_values.pants_workdir,
            log_level=bootstrap_options_values.level,
            server=server,
            core=core,
            metadata_base_dir=bootstrap_options_values.pants_subprocessdir,
            bootstrap_options=bootstrap_options,
        )
示例#5
0
def test_close_stdio(mock_close):
    mock_options = unittest.mock.Mock()
    mock_options_values = unittest.mock.Mock()
    mock_options.for_global_scope.return_value = mock_options_values
    mock_options_values.pants_subprocessdir = "non_existent_dir"
    mock_server = unittest.mock.Mock()

    def create_services(bootstrap_options, legacy_graph_scheduler):
        return PantsServices()

    pantsd = PantsDaemon(
        native=Native(),
        work_dir="test_work_dir",
        log_level=logging.INFO,
        server=mock_server,
        core=PantsDaemonCore(create_services),
        metadata_base_dir="/tmp/pants_test_metadata_dir",
        bootstrap_options=mock_options,
    )

    with stdio_as(-1, -1, -1):
        handles = (sys.stdin, sys.stdout, sys.stderr)
        fds = [h.fileno() for h in handles]
        pantsd._close_stdio()
        mock_close.assert_has_calls(unittest.mock.call(x) for x in fds)
        for handle in handles:
            assert handle.closed is True
示例#6
0
    def create(cls,
               options_bootstrapper: OptionsBootstrapper) -> "PantsDaemon":

        with warnings.catch_warnings(record=True):
            bootstrap_options = options_bootstrapper.bootstrap_options
            bootstrap_options_values = bootstrap_options.for_global_scope()

        setup_warning_filtering(bootstrap_options_values.ignore_pants_warnings
                                or [])

        native = Native()
        native.override_thread_logging_destination_to_just_pantsd()

        core = PantsDaemonCore(cls._setup_services)

        server = native.new_nailgun_server(
            bootstrap_options_values.pantsd_pailgun_port,
            DaemonPantsRunner(core),
        )

        return PantsDaemon(
            native=native,
            work_dir=bootstrap_options_values.pants_workdir,
            log_level=bootstrap_options_values.level,
            server=server,
            core=core,
            metadata_base_dir=bootstrap_options_values.pants_subprocessdir,
            bootstrap_options=bootstrap_options,
        )
示例#7
0
    def create(cls, options_bootstrapper: OptionsBootstrapper) -> PantsDaemon:
        # Any warnings that would be triggered here are re-triggered later per-run of Pants, so we
        # silence them.
        with warnings.catch_warnings(record=True):
            bootstrap_options = options_bootstrapper.bootstrap_options
            bootstrap_options_values = bootstrap_options.for_global_scope()

        native = Native()
        native.override_thread_logging_destination_to_just_pantsd()

        executor = PyExecutor(
            *OptionsInitializer.compute_executor_arguments(bootstrap_options_values)
        )
        core = PantsDaemonCore(executor, cls._setup_services)

        server = native.new_nailgun_server(
            executor,
            bootstrap_options_values.pantsd_pailgun_port,
            DaemonPantsRunner(core),
        )

        return PantsDaemon(
            native=native,
            work_dir=bootstrap_options_values.pants_workdir,
            log_level=bootstrap_options_values.level,
            server=server,
            core=core,
            metadata_base_dir=bootstrap_options_values.pants_subprocessdir,
            bootstrap_options=bootstrap_options,
        )
示例#8
0
def test_prepare_scheduler() -> None:
    # A core with no services.
    def create_services(bootstrap_options, graph_scheduler):
        return PantsServices()

    env = CompleteEnvironment({})
    core = PantsDaemonCore(
        create_options_bootstrapper([]),
        PyExecutor(core_threads=2, max_threads=4),
        create_services,
    )

    first_scheduler, first_options_initializer = core.prepare(
        create_options_bootstrapper(["-ldebug"]),
        env,
    )
    second_scheduler, second_options_initializer = core.prepare(
        create_options_bootstrapper(["-lwarn"]),
        env,
    )
    assert first_scheduler is not second_scheduler
    assert first_options_initializer is second_options_initializer
示例#9
0
    def setUp(self):
        super().setUp()
        mock_options = unittest.mock.Mock()
        mock_options_values = unittest.mock.Mock()
        mock_options.for_global_scope.return_value = mock_options_values
        mock_options_values.pants_subprocessdir = "non_existent_dir"
        mock_server = unittest.mock.Mock()

        def create_services(bootstrap_options, legacy_graph_scheduler):
            return PantsServices()

        self.pantsd = PantsDaemon(
            native=Native(),
            work_dir="test_work_dir",
            log_level=logging.INFO,
            server=mock_server,
            core=PantsDaemonCore(create_services),
            metadata_base_dir="/tmp/pants_test_metadata_dir",
            bootstrap_options=mock_options,
        )