def server_thread(): socket, addr = self.server_socket.accept() server = ServerConnection(socket, addr) try: server.recv_message() raise AssertionError("expected exception not raised") except ConnectionError, e: assert_contains(str(e), "VERSION_MISMATCH")
def test_client_bad_write_server_not_available(self): self.server_socket.close() client = self.client_cxn try: client.send_message(("msg", )) raise AssertionError("no exception raised") except ConnectionError, e: assert_contains(str(e), str(self.bind_address[1])) assert_equal(client.connected(), False)
def test_recv_version_error(self, version_msg): msg_socket = MessageSocket(("127.0.0.1", 0), lambda: Mock(), {}) msg_socket.disconnect = Mock() messages = [ (MessageSocket.TYPE_CONTROL, version_msg), ] msg_socket._recv_one_message = lambda: messages.pop(0) try: msg_socket.recv_message() raise AssertionError("expected exception not raised") except ConnectionError, e: expected = version_msg.split(" ", 1)[1] assert_contains(str(e), expected)
def test_client_empty_read(self): def server_thread(): for num in xrange(2): socket, addr = self.server_socket.accept() if num == 1: server = ServerConnection(socket, addr) server.send_message(("second", )) socket.close() self.spawn(server_thread) client = self.client_cxn try: client.recv_message() raise AssertionError("no exception raised") except ConnectionError, e: assert_contains(str(e), str(self.bind_address[1])) assert_equal(client.connected(), False)
def test_bad_proto(self): try: self.registry.get_server_cls("foo://") raise AssertionError except ValueError as e: assert_contains(str(e), "unrecognized protocol")
def test_invalid_version_info(self, version_info): try: MessageSocket(("127.0.0.1", 0), lambda: None, version_info) raise AssertionError("expected exception not raised") except ValueError, e: assert_contains(str(e), "42")
def test_normal_call(self): app = DirtApp("test_normal_call", self.get_settings(), []) edge = APIEdge(app, app.settings) call = Call("debug.status", (), {}, {}) result = edge.execute(call) assert_contains(result, "uptime")
try: server.recv_message() raise AssertionError("expected exception not raised") except ConnectionError, e: assert_contains(str(e), "VERSION_MISMATCH") assert not server.connected() server_done.set(True) self.spawn(server_thread) client.msg_socket.version_info["foo"] = 42 client.send_message(("hello", "world")) try: client.recv_message() raise AssertionError("expected exception not raised") except ConnectionError, e: assert_contains(str(e), "VERSION_MISMATCH") assert not client.connected() server_done.get(timeout=0.01) class TestMessageSocket(object): def test_zlib(self): socket = Mock() msg_socket = MessageSocket(("127.0.0.1", 0), lambda: socket, {}, use_zlib=True) msg_socket.send_message("hello, world!") assert_equal(socket.sendall.call_args[0], ("000015Z:" + "hello, world!".encode("zlib"), )) def test_send_version(self): socket = Mock() msg_socket = MessageSocket(("127.0.0.1", 0), lambda: socket, {
def test_bad_class(self): try: self.registry._get("good://", "bad_cls") raise AssertionError except ValueError as e: assert_contains(str(e), "class not found in")
def test_bad_use(self): try: runloop(42) except ValueError, e: assert_contains(str(e), "@runloop(log)")