Пример #1
0
def test_shell_started_server_stops():
    """Test if executor terminates properly executor with shell=True."""
    executor = HTTPExecutor(http_server_cmd, "http://{0}:{1}/".format(HOST, PORT), timeout=20, shell=True)

    with pytest.raises(socket.error):
        connect_to_server()

    with executor:
        assert executor.running() is True
        connect_to_server()

    assert executor.running() is False

    with pytest.raises(socket.error):
        connect_to_server()
Пример #2
0
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"
Пример #3
0
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"
Пример #4
0
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"
Пример #5
0
def test_shell_started_server_stops():
    """Test if executor terminates properly executor with shell=True."""
    executor = HTTPExecutor(HTTP_NORMAL_CMD,
                            f'http://{HOST}:{PORT}/',
                            timeout=20,
                            shell=True)

    with pytest.raises(socket.error):
        connect_to_server()

    with executor:
        assert executor.running() is True
        connect_to_server()

    assert executor.running() is False

    with pytest.raises(socket.error):
        connect_to_server()
Пример #6
0
def test_shell_started_server_stops():
    """Test if executor terminates properly executor with shell=True."""
    executor = HTTPExecutor(http_server_cmd,
                            'http://{0}:{1}/'.format(HOST, PORT),
                            timeout=20,
                            shell=True)

    with pytest.raises(socket.error):
        connect_to_server()

    with executor:
        assert executor.running() is True
        connect_to_server()

    assert executor.running() is False

    with pytest.raises(socket.error):
        connect_to_server()
Пример #7
0
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()
Пример #8
0
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)
Пример #9
0
def test_slow_method_server_timed_out(method):
    """Check if timeout properly expires."""

    http_method_slow_cmd = (
        f'{sys.executable} {TEST_SERVER_PATH} {HOST}:{PORT} False {method}')
    executor = HTTPExecutor(http_method_slow_cmd,
                            f'http://{HOST}:{PORT}/',
                            method=method,
                            timeout=1)

    with pytest.raises(TimeoutExpired) as exc:
        executor.start()

    assert executor.running() is False
    assert 'timed out after' in str(exc.value)
Пример #10
0
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)
Пример #11
0
def test_fail_if_other_executor_running():
    """Test raising AlreadyRunning exception when port is blocked."""
    executor = HTTPExecutor(http_server_cmd, "http://{0}:{1}/".format(HOST, PORT))
    executor2 = HTTPExecutor(http_server_cmd, "http://{0}:{1}/".format(HOST, PORT))

    with executor:

        assert executor.running() is True

        with pytest.raises(AlreadyRunning):
            executor2.start()

        with pytest.raises(AlreadyRunning) as exc:
            with executor2:
                pass
        assert "seems to be already running" in str(exc)
Пример #12
0
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)
Пример #13
0
def test_fail_if_other_executor_running():
    """Test raising AlreadyRunning exception when port is blocked."""
    executor = HTTPExecutor(
        http_server_cmd, 'http://{0}:{1}/'.format(HOST, PORT),
    )
    executor2 = HTTPExecutor(
        http_server_cmd, 'http://{0}:{1}/'.format(HOST, PORT),
    )

    with executor:

        assert executor.running() is True

        with pytest.raises(AlreadyRunning):
            executor2.start()

        with pytest.raises(AlreadyRunning):
            with executor2:
                pass
Пример #14
0
def test_fail_if_other_running():
    """Test raising AlreadyRunning exception when port is blocked."""
    executor = HTTPExecutor(
        HTTP_NORMAL_CMD,
        f'http://{HOST}:{PORT}/',
    )
    executor2 = HTTPExecutor(
        HTTP_NORMAL_CMD,
        f'http://{HOST}:{PORT}/',
    )

    with executor:

        assert executor.running() is True

        with pytest.raises(AlreadyRunning):
            executor2.start()

        with pytest.raises(AlreadyRunning) as exc:
            with executor2:
                pass
        assert 'seems to be already running' in str(exc.value)
Пример #15
0
def test_fail_if_other_executor_running():
    """Test raising AlreadyRunning exception when port is blocked."""
    executor = HTTPExecutor(
        http_server_cmd,
        'http://{0}:{1}/'.format(HOST, PORT),
    )
    executor2 = HTTPExecutor(
        http_server_cmd,
        'http://{0}:{1}/'.format(HOST, PORT),
    )

    with executor:

        assert executor.running() is True

        with pytest.raises(AlreadyRunning):
            executor2.start()

        with pytest.raises(AlreadyRunning) as exc:
            with executor2:
                pass
        assert 'seems to be already running' in str(exc)