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
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
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
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
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) ]
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)]
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)]
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
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
def test_socket_connect_unix(self): server = "/tmp/memcache" with MockUnixSocket(server): client = Client(server) assert client._use_unix_socket client._connect()