public void PLayerJoinLobbyFullProtocolTest() { //Create a SubSystem with dummy factory. dummyCoversationFactory dumConvoFact1 = new dummyCoversationFactory(); LobbyAppState lobbyAppState = new LobbyAppState(); SubSystem commSubSysLobby = new SubSystem(dumConvoFact1, lobbyAppState); WaitingRoom waitingRoom = new WaitingRoom(); PlayerAppState playerAppState = new PlayerAppState(waitingRoom); SubSystem commSubSysPlayer = new SubSystem(dumConvoFact1, playerAppState); //Set the name of the player in the App State. playerAppState.playerName = "Tester Testerson"; //get the initial process id. This test will check that the conversation changes it. int startingProcessId = commSubSysPlayer.ProcessID; //Create Initiator conversation PlayerJoinLobby PlayerJoinLobby = new PlayerJoinLobby(); PlayerJoinLobby.SubSystem = commSubSysPlayer; PlayerJoinLobby.RemoteEndPoint = new IPEndPoint(IPAddress.Parse("1.1.1.1"), 1111); ////Create Responder Conversation RespondJoinLobby resJoinLobbyConvo = new RespondJoinLobby(); resJoinLobbyConvo.SubSystem = commSubSysLobby; resJoinLobbyConvo.RemoteEndPoint = new IPEndPoint(IPAddress.Parse("2.2.2.2"), 2222); //Start Initiator Conversation PlayerJoinLobby.Launch(); //Wait for conversation to send message. Thread.Sleep(500); //Check for outgoing message. Assert.IsTrue(commSubSysPlayer.outQueue.Count >= 1); //Get message and put into responder conversation Envelope initiatorEnv; if (!commSubSysPlayer.outQueue.TryDequeue(out initiatorEnv)) { Assert.Fail(); } resJoinLobbyConvo.IncomingEnvelope = initiatorEnv; resJoinLobbyConvo.ConversationId = initiatorEnv.Message.ConversationId; //Start the responder conversation resJoinLobbyConvo.Launch(); //Wait for conversation to send message Thread.Sleep(500); //Check for outgoing message from responder conversation. Assert.IsTrue(commSubSysLobby.outQueue.Count >= 1); //Get responder reply and give to initiator. Envelope responderEnv; if (!commSubSysLobby.outQueue.TryDequeue(out responderEnv)) { Assert.Fail(); } PlayerJoinLobby.Process(responderEnv); //Check that the process Id was changed. Note: This is the Assert.IsTrue(startingProcessId == commSubSysPlayer.ProcessID); Console.WriteLine(startingProcessId); Console.WriteLine(commSubSysLobby.ProcessID); //Check that the GM was added to the Lobby. Assert.IsTrue(lobbyAppState.Pls.Count >= 1); //Close the communicators for next test. commSubSysLobby.udpcomm.closeCommunicator(); commSubSysLobby.tcpcomm.closeCommunicator(); }
public void PlayerJoinLobbyConvoRetries() { //Create a SubSystem with dummy factory. dummyCoversationFactory dumConvoFact = new dummyCoversationFactory(); WaitingRoom waitingRoom = new WaitingRoom(); PlayerAppState playerAppState = new PlayerAppState(waitingRoom); SubSystem commSubSysPlayer = new SubSystem(dumConvoFact, playerAppState); //Note: we dont want to start the threads of the subSystem. //Set the name of the player playerAppState.playerName = "Tester Testerson"; //Create conversation PlayerJoinLobby playerJoinLobbyConvo = new PlayerJoinLobby(); playerJoinLobbyConvo.SubSystem = commSubSysPlayer; playerJoinLobbyConvo.RemoteEndPoint = new IPEndPoint(IPAddress.Parse("1.1.1.1"), 1111); //This is just a dummpy endpoint. Because the TCP and UDP thread are running it may actually send. //Start conversation playerJoinLobbyConvo.Launch(); //Wait one second. Thread.Sleep(1000); //Check outQ for outgoing messages. Assert.IsTrue(commSubSysPlayer.outQueue.Count >= 1); //Wait for retry Thread.Sleep(2000); //Chekc outQ for multiple outgoing messages. Assert.IsTrue(commSubSysPlayer.outQueue.Count >= 2); Thread.Sleep(2000); Assert.IsTrue(commSubSysPlayer.outQueue.Count >= 3); //Make sure those messages are the same. Envelope env1; if (!commSubSysPlayer.outQueue.TryDequeue(out env1)) { Assert.Fail(); } Envelope env2; if (!commSubSysPlayer.outQueue.TryDequeue(out env2)) { Assert.Fail(); } Envelope env3; if (!commSubSysPlayer.outQueue.TryDequeue(out env3)) { Assert.Fail(); } //Make sure the message in the outQ are the same. Assert.IsTrue(env1.Message.ConversationId.Equals(env2.Message.ConversationId) && env1.Message.MessageNumber.Equals(env2.Message.MessageNumber)); Assert.IsTrue(env1.Message.ConversationId.Equals(env3.Message.ConversationId) && env1.Message.MessageNumber.Equals(env3.Message.MessageNumber)); //Close the communicators for next test. commSubSysPlayer.udpcomm.closeCommunicator(); commSubSysPlayer.tcpcomm.closeCommunicator(); }