Git Product home page Git Product logo

Comments (6)

DanCardin avatar DanCardin commented on May 24, 2024

Is pytest-mock-resources timing out or hanging? or what does "dont start" mean.

I know in the past i've needed to docker pull redis:5.0.7 ahead of running the tests due to slow network speed. if you dont have the image in question ahead of time it will pull it and potentially introduce longer startup time than we allow for in our timeouts.

from pytest-mock-resources.

nische avatar nische commented on May 24, 2024

Thanks for your answer

The Image is already on my system.
The package throws the exeption below. And if i watch docker desktop gui the container dont start (and it did before the update).
The exception says redis cant connect but i belief the problem is that the container is not started.

self = Connection<host=host.docker.internal,port=6380,db=0>
    def connect(self):
        "Connects to the Redis server if not already connected"
        if self._sock:
            return
        try:
>           sock = self.retry.call_with_retry(
                lambda: self._connect(), lambda error: self.disconnect(error)
            )
.venv\lib\site-packages\redis\connection.py:259: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
.venv\lib\site-packages\redis\retry.py:51: in call_with_retry
    raise error
.venv\lib\site-packages\redis\retry.py:46: in call_with_retry
    return do()
.venv\lib\site-packages\redis\connection.py:260: in <lambda>
    lambda: self._connect(), lambda error: self.disconnect(error)
.venv\lib\site-packages\redis\connection.py:617: in _connect
    raise err
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = Connection<host=host.docker.internal,port=6380,db=0>
    def _connect(self):
        "Create a TCP socket connection"
        # we want to mimic what socket.create_connection does to support
        # ipv4/ipv6, but we want to set options prior to calling
        # socket.connect()
        err = None
        for res in socket.getaddrinfo(
            self.host, self.port, self.socket_type, socket.SOCK_STREAM
        ):
            family, socktype, proto, canonname, socket_address = res
            sock = None
            try:
                sock = socket.socket(family, socktype, proto)
                # TCP_NODELAY
                sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
    
                # TCP_KEEPALIVE
                if self.socket_keepalive:
                    sock.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
                    for k, v in self.socket_keepalive_options.items():
                        sock.setsockopt(socket.IPPROTO_TCP, k, v)
    
                # set the socket_connect_timeout before we connect
                sock.settimeout(self.socket_connect_timeout)
    
                # connect
>               sock.connect(socket_address)
E               TimeoutError: [WinError 10060] Ein Verbindungsversuch ist fehlgeschlagen, da die Gegenstelle nach einer bestimmten Zeitspanne nicht richtig reagiert hat, oder die hergestellte Verbindung war fehlerhaft, da der verbundene Host nicht reagiert hat
.venv\lib\site-packages\redis\connection.py:605: TimeoutError
During handling of the above exception, another exception occurred:
pytestconfig = <_pytest.config.Config object at 0x0000022026CC5CC0>
pmr_redis_config = RedisConfig(image='redis:6.0', host='host.docker.internal', port=6380, ci_port=6379)
    @pytest.fixture(scope="session")
    def pmr_redis_container(pytestconfig, pmr_redis_config):
>       yield from get_container(pytestconfig, pmr_redis_config)
.venv\lib\site-packages\pytest_mock_resources\fixture\redis.py:23: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
.venv\lib\site-packages\pytest_mock_resources\container\base.py:106: in get_container
    container = wait_for_container(
.venv\lib\site-packages\pytest_mock_resources\container\base.py:145: in wait_for_container
    retry(check_fn, retries=1, interval=interval, on_exc=ContainerCheckFailed)
.venv\lib\site-packages\pytest_mock_resources\container\base.py:66: in retry
    result = func(*args, **kwargs)
.venv\lib\site-packages\pytest_mock_resources\container\redis.py:35: in check_fn
    client.ping()
.venv\lib\site-packages\redis\commands\core.py:1216: in ping
    return self.execute_command("PING", **kwargs)
.venv\lib\site-packages\redis\client.py:505: in execute_command
    conn = self.connection or pool.get_connection(command_name, **options)
.venv\lib\site-packages\redis\connection.py:1073: in get_connection
    connection.connect()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = Connection<host=host.docker.internal,port=6380,db=0>
    def connect(self):
        "Connects to the Redis server if not already connected"
        if self._sock:
            return
        try:
            sock = self.retry.call_with_retry(
                lambda: self._connect(), lambda error: self.disconnect(error)
            )
        except socket.timeout:
>           raise TimeoutError("Timeout connecting to server")
E           redis.exceptions.TimeoutError: Timeout connecting to server
.venv\lib\site-packages\redis\connection.py:263: TimeoutError

from pytest-mock-resources.

DanCardin avatar DanCardin commented on May 24, 2024

Perhaps a docker system prune -a? If it's failing to spin up the container at the docker level, it's beyond the scope of what PMR can affect the outcome of. Particularly if it was a Docker Desktop upgrade, that pretty much guarantees it's unrelated to the inner workings of this library.

from pytest-mock-resources.

nische avatar nische commented on May 24, 2024

pruning the system doesnt fix it. And i have the same error on the new notebook of my colleague.

Did you have any idee?

from pytest-mock-resources.

DanCardin avatar DanCardin commented on May 24, 2024

The only other thing I can think of is that the host correct for your docker setup. If you can import python_on_whales or docker-py, construct a client yourself, and create a container yourself, then it's almost certainly that you need to explicitly export the PYTEST_MOCK_RESOURCES_HOST env var to a different value.

If that doesnt work, then the problem is definitely outside PMR itself.

from pytest-mock-resources.

nische avatar nische commented on May 24, 2024

That's what I do last week. I use pytest-docker and create the Redis service with this as a fixture. 👍

I wish you a Merry Christmas and a happy new year.

Br, Nische

from pytest-mock-resources.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.