Ejemplo n.º 1
0
// Echo 测试
func tstEcho() {
	tstfun := "tstEcho"
	util.LogInfo("<<<<<<%s TEST", tstfun)
	syn := &pushproto.Talk{
		Type:    pushproto.Talk_ECHO.Enum(),
		Extdata: []byte("JUST ECHO"),
	}

	data, err := proto.Marshal(syn)
	if err != nil {
		util.LogError("%s ERROR:proto marshal error:%s", tstfun, err)
		return
	}

	sb := util.Packdata(data)
	tstErr(tstfun, sb, 1, func(pb *pushproto.Talk) {
		pb_type := pb.GetType()
		if pb_type == pushproto.Talk_ECHO {
			util.LogInfo(">>>>>>%s PASS: %s", tstfun, string(pb.GetExtdata()))
		} else {
			util.LogError("%s ERROR", tstfun)
		}

	})

}
Ejemplo n.º 2
0
// 多个连接使用同样的clientid,老的被剔除
func tstDupClient() {
	tstfun := "tstDupClient"
	util.LogInfo("<<<<<<%s TEST", tstfun)

	syn := &pushproto.Talk{
		Type:       pushproto.Talk_SYN.Enum(),
		Appid:      proto.String("shawn"),
		Installid:  proto.String("1cf52f542ec2f6d1e96879bd6f5243da3baa42e4"),
		Auth:       proto.String("F**k"),
		Clienttype: proto.String("Android"),
		Clientver:  proto.String("1.0.0"),
	}

	data, err := proto.Marshal(syn)
	if err != nil {
		util.LogError("%s ERROR:syn proto marshal error:%s", tstfun, err)
		return
	}

	sb := util.Packdata(data)

	first_conn_read := 0
	go tstErr(tstfun, sb, 10, func(pb *pushproto.Talk) {
		pb_type := pb.GetType()
		if first_conn_read == 0 {
			if pb_type == pushproto.Talk_SYNACK {
				util.LogInfo("%s First Conn: client_id:%s", tstfun, pb.GetClientid())
			} else {
				util.LogError("%s First Conn ERROR", tstfun)
				return
			}
			first_conn_read += 1
		} else {
			if pb_type == pushproto.Talk_ERR {
				util.LogInfo(">>>>>>%s First Conn PASS: msg:%s", tstfun, pb.GetExtdata())
			} else {
				util.LogError("%s First Conn ERROR", tstfun)
				return
			}

		}

	})

	time.Sleep(1000 * 1000 * 1000 * 5)

	tstErr(tstfun, sb, 1, func(pb *pushproto.Talk) {
		pb_type := pb.GetType()
		if pb_type == pushproto.Talk_SYNACK {
			util.LogInfo(">>>>>>%s Second Conn PASS: client_id:%s", tstfun, pb.GetClientid())
		} else {
			util.LogError("%s Second Conn ERROR", tstfun)
		}

	})

}
Ejemplo n.º 3
0
// 长度为1数据包
func tstErrOneSizePack() {
	tstfun := "tstErrOneSizePack"
	util.LogInfo("<<<<<<%s TEST", tstfun)
	sb := util.Packdata([]byte("1"))

	tstErr(tstfun, sb, 1, func(pb *pushproto.Talk) {
		pb_type := pb.GetType()
		if pb_type == pushproto.Talk_ERR {
			util.LogInfo(">>>>>>%s PASS: msg:%s", tstfun, pb.GetExtdata())
		} else {
			util.LogError("%s ERROR", tstfun)
		}

	})

}