avast / pytest-docker

Docker-based integration tests
MIT License
427 stars 71 forks source link

getting connection timeout error #50

Closed akshayuppal3 closed 2 years ago

akshayuppal3 commented 4 years ago

Hi Team I am using an HTTP service plugin to check minio service is up and running but I keep getting connection timeout error.

@pytest.fixture(scope="session")
def minio_service(docker_ip, docker_services):

    port = docker_services.port_for("minio", 9000)
    base_url = "http://{}:{}".format(docker_ip, port)
    docker_services.wait_until_responsive(
        timeout=30.0, pause=0.1, check=lambda: is_responsive(base_url + "/minio/health/live")
    )
    time.sleep(5)
    return "{}:{}".format(docker_ip, port)

def is_responsive(url):
    try:
        response = requests.get(url)
        logging.debug(response)
        if response.status_code == 200:
            return True
    except ConnectionError:
        return False

@pytest.fixture(scope="session")
def docker_compose_file(pytestconfig):
    """Point to the docker-compose as the Pybuilder layout is not working
    with the pytest-docker very well"""
    return os.path.join(str(pytestconfig.rootdir), "src/unittest/python", "docker-compose.yml")

I keep getting a connection timeout error. output :

_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <http.client.HTTPResponse object at 0x129881b38>

    def _read_status(self):
        line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
        if len(line) > _MAXLINE:
            raise LineTooLong("status line")
        if self.debuglevel > 0:
            print("reply:", repr(line))
        if not line:
            # Presumably, the server closed the connection before
            # sending a valid response.
>           raise RemoteDisconnected("Remote end closed connection without"
                                     " response")
E           urllib3.exceptions.ProtocolError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))

../../../../anaconda3/lib/python3.7/http/client.py:265: ProtocolError

During handling of the above exception, another exception occurred:

docker_ip = '127.0.0.1'
docker_services = Services(_docker_compose=DockerComposeExecutor(_compose_files=['/Users/akshay.uppalimanage.com/Desktop/MBIs/RI-173/com...ess/src/unittest/python/docker-compose.yml'], _compose_project_name='pytest85559'), _services={'minio': {9000: 32823}})

    @pytest.fixture(scope="session")
    def minio_service(docker_ip, docker_services):
        """Ensure that Minio service is up and responsive. Return the endpoint"""

        # `port_for` takes a container port and returns the corresponding host port
        port = docker_services.port_for("minio", 9000)
        base_url = "http://{}:{}".format(docker_ip, port)
        docker_services.wait_until_responsive(
>           timeout=5.0, pause=0.1, check=lambda: is_responsive(base_url + "/minio/health/live")
        )

src/unittest/python/conftest.py:44: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
venv/lib/python3.7/site-packages/pytest_docker/plugin.py:99: in wait_until_responsive
    if check():
src/unittest/python/conftest.py:44: in <lambda>
    timeout=5.0, pause=0.1, check=lambda: is_responsive(base_url + "/minio/health/live")
src/unittest/python/conftest.py:21: in is_responsive
    response = requests.get(url)
.pybuilder/plugins/cpython-3.7.3.final.0/lib/python3.7/site-packages/requests/api.py:76: in get
    return request('get', url, params=params, **kwargs)
.pybuilder/plugins/cpython-3.7.3.final.0/lib/python3.7/site-packages/requests/api.py:61: in request
    return session.request(method=method, url=url, **kwargs)
.pybuilder/plugins/cpython-3.7.3.final.0/lib/python3.7/site-packages/requests/sessions.py:530: in request
    resp = self.send(prep, **send_kwargs)
.pybuilder/plugins/cpython-3.7.3.final.0/lib/python3.7/site-packages/requests/sessions.py:643: in send
    r = adapter.send(request, **kwargs)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <requests.adapters.HTTPAdapter object at 0x12a7f9da0>, request = <PreparedRequest [GET]>, stream = False
timeout = Timeout(connect=None, read=None, total=None), verify = True, cert = None, proxies = OrderedDict()

    def send(self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None):
        """Sends PreparedRequest object. Returns Response object.

        :param request: The :class:`PreparedRequest <PreparedRequest>` being sent.
        :param stream: (optional) Whether to stream the request content.
        :param timeout: (optional) How long to wait for the server to send
            data before giving up, as a float, or a :ref:`(connect timeout,
            read timeout) <timeouts>` tuple.
        :type timeout: float or tuple or urllib3 Timeout object
        :param verify: (optional) Either a boolean, in which case it controls whether
            we verify the server's TLS certificate, or a string, in which case it
            must be a path to a CA bundle to use
        :param cert: (optional) Any user-provided SSL certificate to be trusted.
        :param proxies: (optional) The proxies dictionary to apply to the request.
        :rtype: requests.Response
        """

        try:
            conn = self.get_connection(request.url, proxies)
        except LocationValueError as e:
            raise InvalidURL(e, request=request)

        self.cert_verify(conn, request.url, verify, cert)
        url = self.request_url(request, proxies)
        self.add_headers(request, stream=stream, timeout=timeout, verify=verify, cert=cert, proxies=proxies)

        chunked = not (request.body is None or 'Content-Length' in request.headers)

        if isinstance(timeout, tuple):
            try:
                connect, read = timeout
                timeout = TimeoutSauce(connect=connect, read=read)
            except ValueError as e:
                # this may raise a string formatting error.
                err = ("Invalid timeout {}. Pass a (connect, read) "
                       "timeout tuple, or a single float to set "
                       "both timeouts to the same value".format(timeout))
                raise ValueError(err)
        elif isinstance(timeout, TimeoutSauce):
            pass
        else:
            timeout = TimeoutSauce(connect=timeout, read=timeout)

        try:
            if not chunked:
                resp = conn.urlopen(
                    method=request.method,
                    url=url,
                    body=request.body,
                    headers=request.headers,
                    redirect=False,
                    assert_same_host=False,
                    preload_content=False,
                    decode_content=False,
                    retries=self.max_retries,
                    timeout=timeout
                )

            # Send the request.
            else:
                if hasattr(conn, 'proxy_pool'):
                    conn = conn.proxy_pool

                low_conn = conn._get_conn(timeout=DEFAULT_POOL_TIMEOUT)

                try:
                    low_conn.putrequest(request.method,
                                        url,
                                        skip_accept_encoding=True)

                    for header, value in request.headers.items():
                        low_conn.putheader(header, value)

                    low_conn.endheaders()

                    for i in request.body:
                        low_conn.send(hex(len(i))[2:].encode('utf-8'))
                        low_conn.send(b'\r\n')
                        low_conn.send(i)
                        low_conn.send(b'\r\n')
                    low_conn.send(b'0\r\n\r\n')

                    # Receive the response from the server
                    try:
                        # For Python 2.7, use buffering of HTTP responses
                        r = low_conn.getresponse(buffering=True)
                    except TypeError:
                        # For compatibility with Python 3.3+
                        r = low_conn.getresponse()

                    resp = HTTPResponse.from_httplib(
                        r,
                        pool=conn,
                        connection=low_conn,
                        preload_content=False,
                        decode_content=False
                    )
                except:
                    # If we hit any problems here, clean up the connection.
                    # Then, reraise so that we can handle the actual exception.
                    low_conn.close()
                    raise

        except (ProtocolError, socket.error) as err:
>           raise ConnectionError(err, request=request)
E           requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))

.pybuilder/plugins/cpython-3.7.3.final.0/lib/python3.7/site-packages/requests/adapters.py:498: ConnectionError