Ejemplo n.º 1
0
    def test_socket_connect_unix(self):
        server = '/tmp/pymemcache.{pid}'.format(pid=os.getpid())

        with MockUnixSocketServer(server):
            client = Client(server)
            client._connect()
            assert client.sock.family == socket.AF_UNIX
Ejemplo n.º 2
0
    def test_socket_connect_unix(self):
        server = '/tmp/pymemcache.{pid}'.format(pid=os.getpid())

        with MockUnixSocketServer(server):
            client = Client(server)
            client._connect()
            assert client.sock.family == socket.AF_UNIX
Ejemplo n.º 3
0
    def test_socket_close(self):
        server = ("example.com", 11211)

        client = Client(server, socket_module=MockSocketModule())
        client._connect()
        assert client.sock is not None

        client.close()
        assert client.sock is None
Ejemplo n.º 4
0
    def test_socket_close(self):
        server = ("example.com", 11211)

        client = Client(server, socket_module=MockSocketModule())
        client._connect()
        assert client.sock is not None

        client.close()
        assert client.sock is None
Ejemplo n.º 5
0
    def test_socket_close_exception(self):
        server = ("example.com", 11211)

        socket_module = MockSocketModule(close_failure=OSError())
        client = Client(server, socket_module=socket_module)
        client._connect()
        assert client.sock is not None

        client.close()
        assert client.sock is None
Ejemplo n.º 6
0
    def test_socket_connect_closes_on_failure(self):
        server = ("example.com", 11211)

        socket_module = MockSocketModule(connect_failure=OSError())
        client = Client(server, socket_module=socket_module)
        with pytest.raises(OSError):
            client._connect()
        assert len(socket_module.sockets) == 1
        assert socket_module.sockets[0].connections == []
        assert socket_module.sockets[0].closed
Ejemplo n.º 7
0
    def test_socket_connect_closes_on_failure(self):
        server = ("example.com", 11211)

        socket_module = MockSocketModule(connect_failure=OSError())
        client = Client(server, socket_module=socket_module)
        with pytest.raises(OSError):
            client._connect()
        assert len(socket_module.sockets) == 1
        assert socket_module.sockets[0].connections == []
        assert socket_module.sockets[0].closed
Ejemplo n.º 8
0
    def test_socket_close_exception(self):
        server = ("example.com", 11211)

        socket_module = MockSocketModule(close_failure=OSError())
        client = Client(server, socket_module=socket_module)
        client._connect()
        assert client.sock is not None

        client.close()
        assert client.sock is None
Ejemplo n.º 9
0
    def test_socket_connect(self):
        server = ("example.com", 11211)

        client = Client(server, socket_module=MockSocketModule())
        client._connect()
        assert client.sock.connections == [server]

        timeout = 2
        connect_timeout = 3
        client = Client(
            server,
            connect_timeout=connect_timeout,
            timeout=timeout,
            socket_module=MockSocketModule(),
        )
        client._connect()
        assert client.sock.timeouts == [connect_timeout, timeout]

        client = Client(server, socket_module=MockSocketModule())
        client._connect()
        assert client.sock.socket_options == []

        client = Client(server, socket_module=MockSocketModule(), no_delay=True)
        client._connect()
        assert client.sock.socket_options == [
            (socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
        ]
Ejemplo n.º 10
0
    def test_socket_connect(self):
        server = ("example.com", 11211)

        client = Client(server, socket_module=MockSocketModule())
        client._connect()
        assert client.sock.connections == [server]

        timeout = 2
        connect_timeout = 3
        client = Client(server,
                        connect_timeout=connect_timeout,
                        timeout=timeout,
                        socket_module=MockSocketModule())
        client._connect()
        assert client.sock.timeouts == [connect_timeout, timeout]

        client = Client(server, socket_module=MockSocketModule())
        client._connect()
        assert client.sock.socket_options == []

        client = Client(server,
                        socket_module=MockSocketModule(),
                        no_delay=True)
        client._connect()
        assert client.sock.socket_options == [(socket.IPPROTO_TCP,
                                               socket.TCP_NODELAY, 1)]
Ejemplo n.º 11
0
    def test_socket_connect_ipv6(self):
        server = ('::1', 11211)

        client = Client(server, socket_module=MockSocketModule())
        client._connect()
        assert client.sock.connections == [server + (0, 0)]
        assert client.sock.family == socket.AF_INET6

        timeout = 2
        connect_timeout = 3
        client = Client(server,
                        connect_timeout=connect_timeout,
                        timeout=timeout,
                        socket_module=MockSocketModule())
        client._connect()
        assert client.sock.timeouts == [connect_timeout, timeout]

        client = Client(server, socket_module=MockSocketModule())
        client._connect()
        assert client.sock.socket_options == []

        client = Client(server,
                        socket_module=MockSocketModule(),
                        no_delay=True)
        client._connect()
        assert client.sock.socket_options == [(socket.IPPROTO_TCP,
                                               socket.TCP_NODELAY, 1)]
Ejemplo n.º 12
0
 def make_client(self, mock_socket_values, **kwargs):
     client = Client(None, **kwargs)
     # mock out client._connect() rather than hard-settting client.sock to
     # ensure methods are checking whether self.sock is None before
     # attempting to use it
     sock = MockSocket(list(mock_socket_values))
     client._connect = mock.Mock(side_effect=functools.partial(
         setattr, client, "sock", sock))
     return client
Ejemplo n.º 13
0
 def make_client(self, mock_socket_values, **kwargs):
     client = Client(None, **kwargs)
     # mock out client._connect() rather than hard-settting client.sock to
     # ensure methods are checking whether self.sock is None before
     # attempting to use it
     sock = MockSocket(list(mock_socket_values))
     client._connect = mock.Mock(side_effect=functools.partial(
         setattr, client, "sock", sock))
     return client
Ejemplo n.º 14
0
 def make_base_client(self, mock_socket_values, **kwargs):
     """ Creates a regular mock client to wrap in the RetryClient. """
     base_client = Client(None, **kwargs)
     # mock out client._connect() rather than hard-settting client.sock to
     # ensure methods are checking whether self.sock is None before
     # attempting to use it
     sock = MockSocket(list(mock_socket_values))
     base_client._connect = mock.Mock(
         side_effect=functools.partial(setattr, base_client, "sock", sock))
     return base_client
Ejemplo n.º 15
0
 def test_socket_connect_unix(self):
     server = "/tmp/memcache"
     with MockUnixSocket(server):
         client = Client(server)
         assert client._use_unix_socket
         client._connect()