package cmd import ( "fmt" "os" "os/signal" "samba/pkg/log" "samba/pkg/servername" "samba/proto" "samba/server/cacheta/handler" . "samba/server/cacheta/service" "samba/util/config" "samba/util/routingKey" "samba/util/util" "syscall" "testing" "time" ) //var token = "" // 初始化环境 func initEnv() { config.Cmd = config.Command{ LogLevel: -1, ConfigPath: "D:\\work\\samba\\samba\\bin\\config\\catheta_dev.xml", } initLog(&config.Cmd) var err = config.Load(config.Cmd.ConfigPath) if err != nil { log.Error(fmt.Sprintf("load config err: %v", err)) } initRepo() handler.InitService() } // 释放环境 func releaseEnv() { c := make(chan os.Signal, 1) signal.Notify(c, syscall.SIGINT, syscall.SIGTERM) sig := <-c handler.StopService() log.Info(fmt.Sprintf("received %s, initiating shutdown...\n", sig)) } func testMatchGame(_ *testing.T, roomType int, uid int64, token string) { SendMsg(util.Direct(servername.Hall), routingKey.Hall, 0, token, uid, proto.ReqMatchRoomId, &proto.ReqMatchRoom{RoomType: roomType}) } // 测试匹配 func TestMatchGame(t *testing.T) { initEnv() uid1 := int64(13143970) uid2 := int64(13182400) var roomType = 10061 //stub.Rooms[roomType].MinPlayers = 2 var token = "" testMatchGame(t, roomType, uid1, token) testMatchGame(t, roomType, uid2, token) time.Sleep(10 * time.Minute) releaseEnv() } func testMatchClub(_ *testing.T, roomType int, uid int64, token string) { SendMsg(util.Direct(servername.Hall), routingKey.Hall, 0, token, uid, proto.ReqMatchClubRoomId, &proto.ReqMatchClubRoom{RoomType: roomType, ClubId: 10000}) } // 测试俱乐部匹配 func TestMatchClubGame(t *testing.T) { initEnv() uid1 := int64(13143970) uid2 := int64(13182400) var roomType = 10061 var token = "" testMatchClub(t, roomType, uid1, token) testMatchClub(t, roomType, uid2, token) time.Sleep(10 * time.Minute) releaseEnv() }