def local_matrix_server(transport_config): if not transport_config.protocol == TransportProtocol.MATRIX: yield None return server = transport_config.parameters.server # if command is none, assume server is already running if transport_config.parameters.command in (None, 'none'): yield server return # otherwise, run our own local server matrix = HTTPExecutor( transport_config.parameters.command, status=r'^[24]\d\d$', url=urljoin(server, '/_matrix'), timeout=120, sleep=0.1, shell=True, ) matrix.start() yield server matrix.stop()
def test_executor_starts_and_waits(): """Test if process awaits for HEAD request to be completed.""" command = 'bash -c "sleep 3 && {0}"'.format(http_server_cmd) executor = HTTPExecutor( command, 'http://{0}:{1}/'.format(HOST, PORT), timeout=20 ) executor.start() assert executor.running() is True connect_to_server() executor.stop()
def test_executor_starts_and_waits(): """Test if process awaits for HEAD request to be completed.""" command = f'bash -c "sleep 3 && {HTTP_NORMAL_CMD}"' executor = HTTPExecutor(command, f'http://{HOST}:{PORT}/', timeout=20) executor.start() assert executor.running() is True connect_to_server() executor.stop() # check proper __str__ and __repr__ rendering: assert 'HTTPExecutor' in repr(executor) assert command in str(executor)
def test_executor_starts_and_waits(): """Test if process awaits for HEAD request to be completed.""" command = 'bash -c "sleep 3 && {0}"'.format(http_server_cmd) executor = HTTPExecutor(command, "http://{0}:{1}/".format(HOST, PORT), timeout=20) executor.start() assert executor.running() is True connect_to_server() executor.stop() # check proper __str__ and __repr__ rendering: assert "HTTPExecutor" in repr(executor) assert command in str(executor)
def test_default_port(): """ Test default port for the base TCP check. Check if HTTP executor fills in the default port for the TCP check from the base class if no port is provided in the URL. """ executor = HTTPExecutor(HTTP_NORMAL_CMD, f'http://{HOST}/') assert executor.url.port is None assert executor.port == PORT assert TCPExecutor.pre_start_check(executor) is False executor.start() assert TCPExecutor.pre_start_check(executor) is True executor.stop()
def test_default_port(): """ Test default port for the base TCP check. Check if HTTP executor fills in the default port for the TCP check from the base class if no port is provided in the URL. """ executor = HTTPExecutor(http_server_cmd, 'http://{}/'.format(HOST)) assert executor.url.port is None assert executor.port == PORT assert TCPExecutor.pre_start_check(executor) is False executor.start() assert TCPExecutor.pre_start_check(executor) is True executor.stop()
def test_default_port(): """ Test default port for the base TCP check. Check if HTTP executor fills in the default port for the TCP check from the base class if no port is provided in the URL. """ executor = HTTPExecutor(http_server_cmd, 'http://{0}/'.format(HOST)) assert executor.url.port is None assert executor.port == PORT assert TCPExecutor.pre_start_check(executor) is False executor.start() assert TCPExecutor.pre_start_check(executor) is True executor.stop()
def test_stopping_brutally(): """ Test if SimpleExecutor is stopping insubordinate process. Check if the process that doesn't react to SIGTERM signal will be killed by executor with SIGKILL automatically. """ host_port = "127.0.0.1:8000" cmd = f"{sys.executable} {TEST_SERVER_PATH} {host_port} True" executor = HTTPExecutor(cmd, f"http://{host_port!s}/", timeout=20) executor.start() assert executor.running() is True stop_at = time.time() + 10 executor.stop() assert executor.running() is False assert stop_at <= time.time(), "Subprocess killed earlier than in 10 secs"
def test_stopping_brutally(): """ Test if SimpleExecutor is stopping insubordinate process. Check if the process that doesn't react to SIGTERM signal will be killed by executor with SIGKILL automatically. """ host_port = "127.0.0.1:8000" cmd = '{} {} {} True'.format(sys.executable, test_server_path, host_port) executor = HTTPExecutor(cmd, 'http://%s/' % host_port) executor.start() assert executor.running() is True stop_at = time.time() + 10 executor.stop() assert executor.running() is False assert stop_at <= time.time(), "Subprocess killed earlier than in 10 secs"
def test_stopping_brutally(): """ Test if Executor is stopping insubordinate process. Check if the process that doesn't react to SIGTERM signal will be killed by executor with SIGKILL automatically. """ host_port = "127.0.0.1:8000" cmd = '{} {} {} True'.format(sys.executable, test_server_path, host_port) executor = HTTPExecutor(cmd, 'http://%s/' % host_port) executor.start() assert executor.running() is True stop_at = time.time() + 10 executor.stop() assert executor.running() is False assert stop_at <= time.time(), "Subprocess killed earlier than in 10 secs"
def test_executor_starts_and_waits(): """Test if process awaits for HEAD request to be completed.""" command = 'bash -c "sleep 3 && {0}"'.format(http_server_cmd) executor = HTTPExecutor(command, 'http://{0}:{1}/'.format(HOST, PORT), timeout=20) executor.start() assert executor.running() is True connect_to_server() executor.stop() # check proper __str__ and __repr__ rendering: assert 'HTTPExecutor' in repr(executor) assert command in str(executor)
def test_http_status_codes(accepted_status, expected_timeout): """ Test how 'status' argument influences executor start. :param int|str accepted_status: Executor 'status' value :param bool expected_timeout: if Executor raises TimeoutExpired or not """ kwargs: Dict[str, Any] = { 'command': HTTP_NORMAL_CMD, 'url': f'http://{HOST}:{PORT}/badpath', 'timeout': 2 } if accepted_status: kwargs['status'] = accepted_status executor = HTTPExecutor(**kwargs) if not expected_timeout: executor.start() executor.stop() else: with pytest.raises(TimeoutExpired): executor.start() executor.stop()
def test_http_status_codes(accepted_status, expected_timeout): """ Test how 'status' argument influences executor start. :param int|str accepted_status: Executor 'status' value :param bool expected_timeout: if Executor raises TimeoutExpired or not """ kwargs = { 'command': http_server_cmd, 'url': 'http://{0}:{1}/badpath'.format(HOST, PORT), 'timeout': 2 } if accepted_status: kwargs['status'] = accepted_status executor = HTTPExecutor(**kwargs) if not expected_timeout: executor.start() executor.stop() else: with pytest.raises(TimeoutExpired): executor.start() executor.stop()
def es_process(es_binary, es_version): port = port_for.select_random() pid = es_binary + '.pid' # use a different garbage collector for better performance os.environ['ES_JAVA_OPTS'] = \ '-Xms1g -Xmx1g -XX:-UseConcMarkSweepGC -XX:+UseG1GC' command = ( f"{es_binary} -p {pid} -E http.port={port} " f"-E xpack.monitoring.enabled=false " f"-E xpack.monitoring.collection.enabled=false " f"> /dev/null" ) url = f'http://127.0.0.1:{port}/_cluster/health?wait_for_status=green' executor = HTTPExecutor(command, url, method='GET', shell=True) executor.start() yield executor executor.stop() executor.kill()
def test_http_status_codes(accepted_status: Union[None, int, str], expected_timeout: bool) -> None: """ Test how 'status' argument influences executor start. :param int|str accepted_status: Executor 'status' value :param bool expected_timeout: if Executor raises TimeoutExpired or not """ kwargs: Dict[str, Any] = { "command": HTTP_NORMAL_CMD, "url": f"http://{HOST}:{PORT}/badpath", "timeout": 2, } if accepted_status: kwargs["status"] = accepted_status executor = HTTPExecutor(**kwargs) if not expected_timeout: executor.start() executor.stop() else: with pytest.raises(TimeoutExpired): executor.start() executor.stop()