Skip to content

Error running test inside a container #25

Closed

Description

@ori-n

Hi,

I'm running my tests as part of the development pipeline inside a container. When I tried test containers I got the following error:
requests.exceptions.ConnectionError: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))

Can someone please help?

Thanks

Activity

  1. aleksandr-kotlyar commented on May 12, 2019

    @aleksandr-kotlyar

    Hi, have the same issue.

    • Scenario:
    1. build image from Dockefile below with the following requirements
    2. run the container
    3. copy tests to container
    4. execute pytest command for tests in container
    • Result: tests fail with errors, with such a log, as below.

    • Expected result: tests are running normally.

    • Requirements:

    pytest==4.1.1
    requests==2.21.0
    selene==1.0.0a13
    testcontainers==2.3
    allure-pytest==2.6.2
    
    • Dockerfile:
    FROM python:3.6.6-alpine3.7
    
    ADD requirements.txt /app/requirements.txt
    
    WORKDIR /app
    
    VOLUME /var/run/docker.sock:/var/run/docker.sock
    
    RUN pip install --no-cache-dir -r requirements.txt
    
    • Detailed log:
    ------------------------------ Captured log setup ------------------------------
    conftest.py                 10 INFO     browser init
    _ ERROR at setup of TestMainSliderControls.test_slider_arrows_both_active_on_the_middle_slides _
    /usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py:600: in urlopen
        chunked=chunked)
    /usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py:354: in _make_request
        conn.request(method, url, **httplib_request_kw)
    /usr/local/lib/python3.6/http/client.py:1239: in request
        self._send_request(method, url, body, headers, encode_chunked)
    /usr/local/lib/python3.6/http/client.py:1285: in _send_request
        self.endheaders(body, encode_chunked=encode_chunked)
    /usr/local/lib/python3.6/http/client.py:1234: in endheaders
        self._send_output(message_body, encode_chunked=encode_chunked)
    /usr/local/lib/python3.6/http/client.py:1026: in _send_output
        self.send(msg)
    /usr/local/lib/python3.6/http/client.py:964: in send
        self.connect()
    /usr/local/lib/python3.6/site-packages/docker/transport/unixconn.py:43: in connect
        sock.connect(self.unix_socket)
    E   FileNotFoundError: [Errno 2] No such file or directory
    
    During handling of the above exception, another exception occurred:
    /usr/local/lib/python3.6/site-packages/requests/adapters.py:449: in send
        timeout=timeout
    /usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py:638: in urlopen
        _stacktrace=sys.exc_info()[2])
    /usr/local/lib/python3.6/site-packages/urllib3/util/retry.py:368: in increment
        raise six.reraise(type(error), error, _stacktrace)
    /usr/local/lib/python3.6/site-packages/urllib3/packages/six.py:685: in reraise
        raise value.with_traceback(tb)
    /usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py:600: in urlopen
        chunked=chunked)
    /usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py:354: in _make_request
        conn.request(method, url, **httplib_request_kw)
    /usr/local/lib/python3.6/http/client.py:1239: in request
        self._send_request(method, url, body, headers, encode_chunked)
    /usr/local/lib/python3.6/http/client.py:1285: in _send_request
        self.endheaders(body, encode_chunked=encode_chunked)
    /usr/local/lib/python3.6/http/client.py:1234: in endheaders
        self._send_output(message_body, encode_chunked=encode_chunked)
    /usr/local/lib/python3.6/http/client.py:1026: in _send_output
        self.send(msg)
    /usr/local/lib/python3.6/http/client.py:964: in send
        self.connect()
    /usr/local/lib/python3.6/site-packages/docker/transport/unixconn.py:43: in connect
        sock.connect(self.unix_socket)
    E   urllib3.exceptions.ProtocolError: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))
    
    During handling of the above exception, another exception occurred:
    more-web-integration-tests/conftest.py:11: in pytest_runtest_setup
        chrome = BrowserWebDriverContainer(DesiredCapabilities.CHROME).start()
    /usr/local/lib/python3.6/site-packages/testcontainers/core/container.py:47: in start
        volumes=self.volumes)
    /usr/local/lib/python3.6/site-packages/testcontainers/core/docker_client.py:37: in run
        **kwargs)
    /usr/local/lib/python3.6/site-packages/docker/models/containers.py:785: in run
        detach=detach, **kwargs)
    /usr/local/lib/python3.6/site-packages/docker/models/containers.py:843: in create
        resp = self.client.api.create_container(**create_kwargs)
    /usr/local/lib/python3.6/site-packages/docker/api/container.py:427: in create_container
        return self.create_container_from_config(config, name)
    /usr/local/lib/python3.6/site-packages/docker/api/container.py:437: in create_container_from_config
        res = self._post_json(u, data=config, params=params)
    /usr/local/lib/python3.6/site-packages/docker/api/client.py:289: in _post_json
        return self._post(url, data=json.dumps(data2), **kwargs)
    /usr/local/lib/python3.6/site-packages/docker/utils/decorators.py:46: in inner
        return f(self, *args, **kwargs)
    /usr/local/lib/python3.6/site-packages/docker/api/client.py:226: in _post
        return self.post(url, **self._set_request_timeout(kwargs))
    /usr/local/lib/python3.6/site-packages/requests/sessions.py:581: in post
        return self.request('POST', url, data=data, json=json, **kwargs)
    /usr/local/lib/python3.6/site-packages/requests/sessions.py:533: in request
        resp = self.send(prep, **send_kwargs)
    /usr/local/lib/python3.6/site-packages/requests/sessions.py:646: in send
        r = adapter.send(request, **kwargs)
    /usr/local/lib/python3.6/site-packages/requests/adapters.py:498: in send
        raise ConnectionError(err, request=request)
    E   requests.exceptions.ConnectionError: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))
    ---------------------------- Captured stdout setup -----------------------------
    
    Pulling image selenium/standalone-chrome-debug:latest
    ------------------------------ Captured log setup ------------------------------
    conftest.py                 10 INFO     browser init
    =========================== 26 error in 7.99 seconds ===========================
    
    • Code:
    import logging
    
    import selene
    from selene import config, browser
    from selenium.webdriver import DesiredCapabilities
    from testcontainers.selenium import BrowserWebDriverContainer
    
    
    def pytest_runtest_setup():
        logging.info('browser init')
        chrome = BrowserWebDriverContainer(DesiredCapabilities.CHROME).start()
        logging.info('browser downloaded')
        with chrome:
            logging.info('get webdriver')
            selene.browser.set_driver(chrome.get_driver())
            logging.info('set webdriver')
            config.timeout = 4
            config.poll_during_waits = 0.05
            config.hold_browser_open = False
            logging.info('browser configured')
    

    What's wrong with the code/configuration?
    I couldn't find any information, except add something like
    VOLUME /var/run/docker.sock:/var/run/docker.sock to Dockerfile. That didn't help.
    Hope that more details will help to figure out the problem.

    Best regards, Aleksandr

  2. aleksandr-kotlyar commented on May 12, 2019

    @aleksandr-kotlyar

    Hi, i have found guide how to use testcontainers in gitlab-ci.
    https://www.testcontainers.org/supported_docker_environment/continuous_integration/gitlab_ci/

    and found a problem when i call chrome.get_driver() from the code above

    -------------------------------- live log setup --------------------------------
    conftest.py                 10 INFO     browser init
    conftest.py                 12 INFO     browser downloaded
    conftest.py                 14 INFO     get webdriver
    remote_connection.py       117 INFO     Could not connect to port 4444 on host 172.18.0.2
    remote_connection.py       136 INFO     Could not get IP address for host: 172.18.0.2
    connectionpool.py          662 WARNING  Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f23312adc18>: Failed to establish a new connection: [Errno 110] Operation timed out',)': /wd/hub/session
    connectionpool.py          662 WARNING  Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f23312a7ef0>: Failed to establish a new connection: [Errno 110] Operation timed out',)': /wd/hub/session
    connectionpool.py          662 WARNING  Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f23312a7550>: Failed to establish a new connection: [Errno 110] Operation timed out',)': /wd/hub/session
    remote_connection.py       117 INFO     Could not connect to port 4444 on host 172.18.0.2
    remote_connection.py       136 INFO     Could not get IP address for host: 172.18.0.2
    connectionpool.py          662 WARNING  Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f2331207780>: Failed to establish a new connection: [Errno 110] Operation timed out',)': /wd/hub/session
    connectionpool.py          662 WARNING  Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f23312070b8>: Failed to establish a new connection: [Errno 110] Operation timed out',)': /wd/hub/session
    

    and this continues to spam.

    May be this is new trouble for the new issue, but still blocks the same purpose: running test inside a container.

    Need a help with understanding what happens here. What these hosts and ports mean?

    Best regards, Aleksandr

  3. tillahoffmann commented on Apr 28, 2020

    @tillahoffmann
    Contributor

    You should be able to use docker-in-docker given the changes in #66 and #85. Feel free to reopen if problems persist after the next release.

  4. ahcub commented on Jun 24, 2020

    @ahcub

    having the same issue as described in the original request
    errors like this one and the related ones
    urllib3.exceptions.ProtocolError: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))

    not sure what is the issue as I added all the required things as per this doc: https://www.testcontainers.org/supported_docker_environment/continuous_integration/gitlab_ci/

  5. pofl commented on Aug 4, 2020

    @pofl

    I ran into this error, not in a CI pipeline but on my laptop. For me the problem was that Docker Desktop wasn't running. After (re)starting Docker Desktop, the error went away.

  6. tillahoffmann commented on Aug 18, 2020

    @tillahoffmann
    Contributor

    @ahcub, an example of a working .gitlab-ci.yml can be found here. Does that help?

  7. ahcub commented on Aug 21, 2020

    @ahcub

    yep, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions