func (s *testClientSuite) TestWrongMessageID(c *C) { l := startServer(":61237", c, func(conn net.Conn, c *C) { var msg msgpb.Message msgID, err := util.ReadMessage(conn, &msg) c.Assert(err, IsNil) resp := msgpb.Message{ MsgType: msgpb.MessageType_KvResp, KvResp: &pb.Response{ Type: msg.GetKvReq().GetType(), }, } // Send the request back to client, set wrong msgID for the 1st // request. if msgID == 1 { err = util.WriteMessage(conn, msgID+100, &resp) } else { err = util.WriteMessage(conn, msgID, &resp) } c.Assert(err, IsNil) }) defer l.Close() cli := newRPCClient() req := &pb.Request{ Type: pb.MessageType_CmdGet, } // Wrong ID for the first request, correct for the rests. _, err := cli.SendKVReq(":61237", req, readTimeoutShort) c.Assert(err, NotNil) resp, err := cli.SendKVReq(":61237", req, readTimeoutShort) c.Assert(err, IsNil) c.Assert(resp.GetType(), Equals, req.GetType()) }
func readThenCloseRequest(conn net.Conn, c *C) { c.Assert(conn, NotNil) defer conn.Close() var msg msgpb.Message msgID, err := util.ReadMessage(conn, &msg) c.Assert(err, IsNil) c.Assert(msg.GetKvReq(), NotNil) c.Assert(msgID, Greater, uint64(0)) }
// handleRequest receive Request then send empty Response back fill with same Type. func handleRequest(conn net.Conn, c *C) { c.Assert(conn, NotNil) defer conn.Close() var msg msgpb.Message msgID, err := util.ReadMessage(conn, &msg) c.Assert(err, IsNil) c.Assert(msgID, Greater, uint64(0)) c.Assert(msg.GetMsgType(), Equals, msgpb.MessageType_KvReq) req := msg.GetKvReq() c.Assert(req, NotNil) var resp pb.Response resp.Type = req.Type msg = msgpb.Message{ MsgType: msgpb.MessageType_KvResp, KvResp: &resp, } err = util.WriteMessage(conn, msgID, &msg) c.Assert(err, IsNil) }