public void GMJoinLobbyConvoRetries() { //Create a SubSystem with dummy factory. dummyCoversationFactory dumConvoFact = new dummyCoversationFactory(); GMAppState lobbyAppState = new GMAppState(); SubSystem commSubSys = new SubSystem(dumConvoFact, lobbyAppState); //Note: we dont want to start the threads of the subSystem. //Create conversation GMJoinLobby GMJoinLobbyConversation = new GMJoinLobby(); GMJoinLobbyConversation.SubSystem = commSubSys; GMJoinLobbyConversation.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 GMJoinLobbyConversation.Launch(); //Wait one second. Thread.Sleep(1000); //Check outQ for outgoing messages. Assert.IsTrue(commSubSys.outQueue.Count >= 1); //Wait for retry Thread.Sleep(2000); //Chekc outQ for multiple outgoing messages. Assert.IsTrue(commSubSys.outQueue.Count >= 2); Thread.Sleep(2000); Assert.IsTrue(commSubSys.outQueue.Count >= 3); //Make sure those messages are the same. Envelope env1; if (!commSubSys.outQueue.TryDequeue(out env1)) { Assert.Fail(); } Envelope env2; if (!commSubSys.outQueue.TryDequeue(out env2)) { Assert.Fail(); } Envelope env3; if (!commSubSys.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. commSubSys.udpcomm.closeCommunicator(); commSubSys.tcpcomm.closeCommunicator(); }
public void GMJoinLobbyFullProtocolTest() { //Create a SubSystem with dummy factory. dummyCoversationFactory dumConvoFact1 = new dummyCoversationFactory(); LobbyAppState lobbyAppState = new LobbyAppState(); GMAppState gMAppState = new GMAppState(); SubSystem commSubSys1 = new SubSystem(dumConvoFact1, lobbyAppState); SubSystem commSubSysGM = new SubSystem(dumConvoFact1, gMAppState, new IPEndPoint(IPAddress.Any, 3001), new IPEndPoint(IPAddress.Any, 3002)); //dummyCoversationFactory dumConvoFact2 = new dummyCoversationFactory(); //SubSystem commSubSys2; //Note: Its a little strange that we are only using one subsystem here. Using two wont work because we have hard coded the Sockets that UDP and TCP are using and we can't bind to the same sockets. //Note: we dont want to start the threads of the subSystem. //get the initial process id. This test will check that the conversation changes it. int startingProcessId = commSubSysGM.ProcessID; //Create Initiator conversation GMJoinLobby GMJoinLobbyConversation = new GMJoinLobby(); GMJoinLobbyConversation.SubSystem = commSubSysGM; GMJoinLobbyConversation.RemoteEndPoint = new IPEndPoint(IPAddress.Parse("1.1.1.1"), 1111); ////Create Responder Conversation RespondJoinLobby resJoinLobbyConvo = new RespondJoinLobby(); resJoinLobbyConvo.SubSystem = commSubSys1; resJoinLobbyConvo.RemoteEndPoint = new IPEndPoint(IPAddress.Parse("2.2.2.2"), 2222); //Start Initiator Conversation GMJoinLobbyConversation.Launch(); //Wait for conversation to send message. Thread.Sleep(500); //Check for outgoing message. Assert.IsTrue(commSubSysGM.outQueue.Count >= 1); //Get message and put into responder conversation Envelope initiatorEnv; if (!commSubSysGM.outQueue.TryDequeue(out initiatorEnv)) { Assert.Fail(); } initiatorEnv.From = commSubSysGM.udpcomm.GetEndPoint(); //Added to resolve a message. 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(commSubSys1.outQueue.Count >= 1); //Get responder reply and give to initiator. Envelope responderEnv; if (!commSubSys1.outQueue.TryDequeue(out responderEnv)) { Assert.Fail(); } GMJoinLobbyConversation.Process(responderEnv); //Check that the process Id was changed. Note: This is the Assert.IsTrue(startingProcessId == commSubSysGM.ProcessID); Console.WriteLine(startingProcessId); Console.WriteLine(commSubSysGM.ProcessID); //Check that the GM was added to the Lobby. Assert.IsTrue(lobbyAppState.GMs.Count >= 1); //Close the communicators for next test. commSubSys1.udpcomm.closeCommunicator(); commSubSys1.tcpcomm.closeCommunicator(); }