func test() bool { flag.Parse() useCentral := len(*gameServerHostPorts) == 0 gsHostPortsSlice := strings.Split(*gameServerHostPorts, ",") if len(gsHostPortsSlice) == 0 && *centralServerHostPort == "" { fmt.Println("ERROR: Invalid configuration. Either specify a central server or a list of game servers.") os.Exit(-1) } // Generate random moves moveList := make([]*lib2048.Move, 0) for i := 0; i < *numMoves; i++ { moveList = append(moveList, util.RandomMove()) } // Start up all command line clients cservAddr := "http://" + *centralServerHostPort clients := make([]cmdlineclient.Cclient, *numClients) gsHostPort := "" for i := 0; i < *numClients; i++ { if !useCentral { gsHostPort = gsHostPortsSlice[i%len(gsHostPortsSlice)] cservAddr = "" } var err error clients[i], err = cmdlineclient.NewCClient(cservAddr, gsHostPort, util.DEFAULTINTERVAL) if err != nil { fmt.Println("FAIL: Command line client could not start:", err) return false } } // Test the moves for i, m := range moveList { fmt.Printf("Sending moves (%d/%d)...\n", i+1, len(moveList)) for i := 0; i < *numSendingClients; i++ { clients[i].InputMove(m.Direction) } time.Sleep(time.Duration(*sendMoveInterval) * time.Millisecond) } // Check that all clients have the same set of moves time.Sleep(7 * time.Second) // Let all network operations complete for i, c := range clients { if !c.GetGameState().Equals(clients[0].GetGameState()) { fmt.Println("FAIL: Game client", i, "differs in state from game client", 0) fmt.Printf("Client %d's state:\n%s\n", i, c.GetGameState().String()) fmt.Printf("Client %d's state:\n%s\n", 0, clients[0].GetGameState().String()) return false } } fmt.Println("PASS") return true }
func testOneCentralOneClientOneGameserv() { // Step 1: Boot Testing Client cservAddr := "http://" + util.CENTRALHOSTPOST cli, err := cmdlineclient.NewCClient(cservAddr, "", util.DEFAULTINTERVAL) processError(err, util.CFAIL) // Step 2: Initialize moves + obtain correct answer movelist := []*lib2048.Move{ lib2048.NewMove(lib2048.Left), lib2048.NewMove(lib2048.Right), lib2048.NewMove(lib2048.Left), lib2048.NewMove(lib2048.Up), lib2048.NewMove(lib2048.Up), lib2048.NewMove(lib2048.Down), lib2048.NewMove(lib2048.Right), lib2048.NewMove(lib2048.Left), } desiredGame := util.CalculateGameState(cli.GetGameState(), movelist) // Step 3: Test for _, m := range movelist { cli.InputMove(m.Direction) time.Sleep(1000 * time.Millisecond) // has to be large enough so one move per paxos round } LOGV.Println("CLI's game state") LOGV.Println(cli.GetGameState()) LOGV.Println("Desired game state") LOGV.Println(desiredGame) if !cli.GetGameState().Equals(desiredGame) { fmt.Println("PHAIL: STATES ARE NOT CORRECTZ") failCount++ return } fmt.Println("PASS") passCount++ }