示例#1
0
def test_check_metrics_env_no_webserver():
    arguments = ["--no-webserver"]
    options = parse_program_options(arguments)
    try:
        _check_metrics_env(options)
    except Exception as e:
        pytest.fail(f"--no-webserver should have skipped the metrics env check, but instead we got an exception {e}")
示例#2
0
    def __init__(
        self,
        conf_path,
        channel_conf_path,
        server_address,
        datasource,
        conf_override=None,
        channel_conf_override=None,
    ):
        """format of args should match what you set in conf_mamanger"""
        super().__init__(name="DETestWorker")
        self.server_address = server_address
        self.conf_path = conf_path
        self.channel_conf_path = channel_conf_path

        self.global_config, self.channel_config_loader = _get_de_conf_manager(
            conf_path, channel_conf_path, parse_program_options([]))

        # Override global configuration for testing
        self.global_config["shutdown_timeout"] = 1
        self.global_config["server_address"] = self.server_address
        self.global_config["dataspace"]["datasource"] = datasource
        self.global_config["no_webserver"] = True

        self.de_server = _create_de_server(self.global_config,
                                           self.channel_config_loader)
        self.stdout_at_setup = None
示例#3
0
def deserver_mock_data_block(mock_data_block):  # noqa: F811
    global_config, channel_config_handler = _get_de_conf_manager(_CONFIG_PATH,
                                                                 _CHANNEL_CONFIG_PATH,
                                                                 parse_program_options([f'--port={_port}']))
    server = _create_de_server(global_config, channel_config_handler)
    server.start_channels()
    server.block_while(State.BOOT)
    yield server
    server.stop_channels()
示例#4
0
def test_check_metrics_env_var_set():
    arguments = []
    options = parse_program_options(arguments)
    try:
        _check_metrics_env(options)
    except Exception as e:
        pytest.fail(
            f"PROMETHEUS_MULTIPROC_DIR should be set, so check_metrics_env should have passed but instead we got an exception {e}"
        )
示例#5
0
    def __init__(
        self,
        conf_path,
        channel_conf_path,
        server_address,
        datasource,
        conf_override=None,
        channel_conf_override=None,
    ):
        """format of args should match what you set in conf_mamanger"""
        super().__init__(name="DETestWorker")
        self.server_address = server_address
        self.conf_path = conf_path
        self.channel_conf_path = channel_conf_path

        self.global_config, self.channel_config_loader = _get_de_conf_manager(
            conf_path, channel_conf_path, parse_program_options([])
        )

        # Because multiple DETestWorkers can be in use concurrently,
        # we assign different database numbers (from 0 through 15 by
        # redis default) where possible to avoid kombu messaging
        # collisions whenever routing keys are the same.

        # If pytest-xdist is being used, and 16 or fewer xdist workers
        # are being used, we can use the number in the worker ID as
        # the database ID.  Otherwise, we assign a random number
        # between 0 and 15 (inclusive).
        db_number = 0
        xdist_worker_count = os.environ.get("PYTEST_XDIST_WORKER_COUNT")
        if xdist_worker_count and int(xdist_worker_count) <= 16:
            worker_id = os.environ["PYTEST_XDIST_WORKER"]
            db_number = re.sub(r"^gw(\d{1,2})", r"\1", worker_id)  # Remove the gw prefix
            assert int(db_number) < 16
        else:
            db_number = random.randrange(0, 16)

        # Override global configuration for testing
        self.global_config["broker_url"] = f"redis://localhost:6379/{db_number}"
        self.global_config["shutdown_timeout"] = 1
        self.global_config["server_address"] = self.server_address
        self.global_config["dataspace"]["datasource"] = datasource
        self.global_config["no_webserver"] = False
        self.global_config["webserver"] = {}
        self.global_config["webserver"]["port"] = get_random_port()

        self.de_server = _create_de_server(self.global_config, self.channel_config_loader)
        self.stdout_at_setup = None
示例#6
0
    def __init__(
        self,
        conf_path,
        channel_conf_path,
        server_address,
        datasource,
        conf_override=None,
        channel_conf_override=None,
    ):
        '''format of args should match what you set in conf_mamanger'''
        super().__init__(name='DETestWorker')
        self.server_address = server_address

        self.global_config, self.channel_config_loader = _get_de_conf_manager(
            conf_path, channel_conf_path, parse_program_options([]))

        # Override global configuration for testing
        self.global_config['shutdown_timeout'] = 1
        self.global_config['server_address'] = self.server_address
        self.global_config['dataspace']['datasource'] = datasource

        self.de_server = _create_de_server(self.global_config,
                                           self.channel_config_loader)
示例#7
0
    def __init__(self,
                 conf_path,
                 channel_conf_path,
                 server_address,
                 db_info,
                 conf_override=None,
                 channel_conf_override=None):
        '''format of args should match what you set in conf_mamanger'''
        super().__init__()
        self.server_address = server_address

        global_config, channel_config_loader = _get_de_conf_manager(
            conf_path, channel_conf_path, parse_program_options([]))

        # Override global configuration for testing
        global_config['shutdown_timeout'] = 1
        global_config['server_address'] = self.server_address
        global_config['dataspace']['datasource']['config'] = db_info

        self.de_server = _create_de_server(global_config,
                                           channel_config_loader)
        self.reaper_start_delay_seconds = global_config['dataspace'].get(
            'reaper_start_delay_seconds', 1818)
示例#8
0
def _check_override(arguments):
    options = parse_program_options(arguments)
    return _get_global_config(global_config_file.name, options)
示例#9
0
def test_check_metrics_env_var_unset():
    arguments = []
    options = parse_program_options(arguments)
    with pytest.raises(EnvironmentError) as excinfo:
        _check_metrics_env(options)
    assert "PROMETHEUS_MULTIPROC_DIR must be set" in str(excinfo.value)