Exemple #1
0
        public void RespondShotRespondingToRetries()
        {
            //Create a SubSystem with dummy factory.
            dummyConversationFactory dumConvoFact = new dummyConversationFactory();
            GMAppState gmAppState = new GMAppState();
            SubSystem  commSubSys = new SubSystem(dumConvoFact, gmAppState);
            //Note: we dont want to start the threads of the subSystem.

            //Create Conversation
            RespondShot respondShot = new RespondShot();

            respondShot.SubSystem      = commSubSys;
            respondShot.RemoteEndPoint = new IPEndPoint(IPAddress.Parse("1.1.1.1"), 1111);
            gmAppState.P1EndPoint      = new IPEndPoint(IPAddress.Parse("1.1.1.1"), 1111);

            //Create fake incoming env.
            Envelope IncomingEnv = new Envelope(new ShotMessage(1, 1, 1, 1, new Identifier(0, 1), new Identifier(0, 1)), new IPEndPoint(IPAddress.Parse("1.1.1.1"), 1111), new IPEndPoint(IPAddress.Parse("2.2.2.2"), 2222), false);

            //Set the incoming env.
            respondShot.IncomingEnvelope = IncomingEnv;
            respondShot.recievedMessagesDict.TryAdd(IncomingEnv.Message.MessageNumber.ToString(), IncomingEnv);

            //Start the conversation
            respondShot.Launch();

            Thread.Sleep(500);

            //check the outgoing message.
            Assert.IsTrue(commSubSys.outQueue.Count >= 1);

            //Give a duplicate message.
            respondShot.Process(IncomingEnv);

            Thread.Sleep(500);

            //check the outgoing message.
            Assert.IsTrue(commSubSys.outQueue.Count >= 2);

            //get count of outgoing messages for later.
            int countOfOutGoingMessages = commSubSys.outQueue.Count;

            //Wait for timeout time
            Thread.Sleep(2000);

            //Check that there are no new messages.
            Assert.IsTrue(countOfOutGoingMessages == commSubSys.outQueue.Count);

            //Cheack that thread has ended.
            respondShot.Process(IncomingEnv); //If thread was running outgoing messages should go up.
            Thread.Sleep(500);
            Assert.IsTrue(countOfOutGoingMessages == commSubSys.outQueue.Count);

            //Close the communicators for next test.
            commSubSys.udpcomm.closeCommunicator();
            commSubSys.tcpcomm.closeCommunicator();
        }
        public void TurnsConvoRetries()
        {
            dummyConversationFactory dumConvoFact = new dummyConversationFactory();
            GMAppState gmAppState = new GMAppState();
            SubSystem  commSubSys = new SubSystem(dumConvoFact, gmAppState);

            Turns turnsConvo = new Turns();

            turnsConvo.SubSystem      = commSubSys;
            turnsConvo.RemoteEndPoint = new IPEndPoint(IPAddress.Parse("1.1.1.1"), 1111);

            turnsConvo.Launch();

            Thread.Sleep(1000);

            Assert.IsTrue(commSubSys.outQueue.Count >= 1);

            Thread.Sleep(2000);

            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 TurnsFullProtocolTest()
        {
            //Create a SubSystem with dummy factory.
            dummyConversationFactory dumConvoFact1 = new dummyConversationFactory();
            GMAppState gmAppState  = new GMAppState();
            SubSystem  commSubSys1 = new SubSystem(dumConvoFact1, gmAppState);
            //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 = commSubSys1.ProcessID;

            //Create Initiator conversation
            Turns turnsConvo = new Turns();

            turnsConvo.SubSystem      = commSubSys1;
            turnsConvo.RemoteEndPoint = new IPEndPoint(IPAddress.Parse("1.1.1.1"), 1111);

            ////Create Responder Conversation
            RespondTurns   respondTurnsConvo = new RespondTurns();
            WaitingRoom    waitingRoom       = new WaitingRoom();
            PlayerAppState playerAppState    = new PlayerAppState(waitingRoom);
            SubSystem      commSubSys2       = new SubSystem(dumConvoFact1, playerAppState);

            respondTurnsConvo.SubSystem      = commSubSys2;
            respondTurnsConvo.RemoteEndPoint = new IPEndPoint(IPAddress.Parse("2.2.2.2"), 2222);

            //Start Initiator Conversation
            turnsConvo.Launch();

            //Wait for conversation to send message.
            Thread.Sleep(500);

            //Check for outgoing message.
            Assert.IsTrue(commSubSys1.outQueue.Count >= 1);

            //Get message and put into responder conversation
            Envelope initiatorEnv;

            if (!commSubSys1.outQueue.TryDequeue(out initiatorEnv))
            {
                Assert.Fail();
            }
            respondTurnsConvo.IncomingEnvelope = initiatorEnv;
            respondTurnsConvo.ConversationId   = initiatorEnv.Message.ConversationId;

            //Start the responder conversation
            respondTurnsConvo.Launch();

            //Wait for conversation to send message
            Thread.Sleep(1000);

            //Check for outgoing message from responder conversation.
            Assert.IsTrue(commSubSys2.outQueue.Count >= 1);

            //Get responder reply and give to initiator.
            Envelope responderEnv;

            if (!commSubSys2.outQueue.TryDequeue(out responderEnv))
            {
                Assert.Fail();
            }
            turnsConvo.Process(responderEnv);

            //Check that the process Id was changed. Note: This is the
            Assert.IsTrue(startingProcessId == commSubSys1.ProcessID);

            //Check that gmAppState is correct
            Assert.AreEqual(gmAppState.gameId, 0);
            Assert.IsTrue(gmAppState.P1turn);

            //Check that playerAppState is correct
            Assert.AreEqual(playerAppState.gameId, 0);
            Assert.IsFalse(playerAppState.lastShotHit);
            Assert.IsTrue(playerAppState.turn);
            Assert.IsFalse(playerAppState.won);

            //Close the communicators for next test.
            commSubSys1.udpcomm.closeCommunicator();
            commSubSys1.tcpcomm.closeCommunicator();
        }
        public void EndGameFull()
        {
            dummyConversationFactory lobbyDumConvoFac = new dummyConversationFactory();
            LobbyAppState            lobbyAppState    = new LobbyAppState();
            SubSystem commSubSysLobby = new SubSystem(lobbyDumConvoFac, lobbyAppState);

            dummyConversationFactory gMDumConvoFac = new dummyConversationFactory();
            GMAppState gMAppState  = new GMAppState();
            SubSystem  comSubSysGM = new SubSystem(gMDumConvoFac, gMAppState);

            //Setting a running game in the lobby appState
            lobbyAppState.addGM(new IPEndPoint(IPAddress.Parse("1.1.1.1"), 1111), new IPEndPoint(IPAddress.Parse("2.2.2.2"), 2222), 5);
            lobbyAppState.addPlayer(new IPEndPoint(IPAddress.Parse("1.1.1.1"), 1111), 1, "name");
            lobbyAppState.addPlayer(new IPEndPoint(IPAddress.Parse("1.1.1.1"), 1111), 2, "something");
            lobbyAppState.startGame(); //pulls the players and GM into game.
            Assert.IsTrue(lobbyAppState.GamesBeingPlayed.Count == 1);

            //Setting the GMID
            gMAppState.gameId = 5;

            //Create the initators conversation
            EndGame endGame = new EndGame();

            endGame.SubSystem      = comSubSysGM;
            endGame.RemoteEndPoint = new IPEndPoint(IPAddress.Parse("1.1.1.1"), 111);

            //Create the responder
            RespondEndGame resEndGame = new RespondEndGame();

            resEndGame.SubSystem      = commSubSysLobby;
            resEndGame.RemoteEndPoint = new IPEndPoint(IPAddress.Parse("2.2.2.2"), 222);

            //Start initiator conversatin
            endGame.Launch();

            //wait for conversation to send message
            Thread.Sleep(1000);

            //Check for outgoing message.
            Assert.IsTrue(comSubSysGM.outQueue.Count >= 1);

            //Get the message from initiator to responder.
            Envelope initiatorEnv;

            if (!comSubSysGM.outQueue.TryDequeue(out initiatorEnv))
            {
                Assert.Fail();
            }
            resEndGame.IncomingEnvelope = initiatorEnv;
            resEndGame.ConversationId   = initiatorEnv.Message.ConversationId;

            //start the responder conversation
            resEndGame.Launch();

            //wait a bit
            Thread.Sleep(1000);

            //Check of a responce from the conversation
            Assert.IsTrue(commSubSysLobby.outQueue.Count >= 1);

            //Get the responderenv
            Envelope responderEnv;

            if (!commSubSysLobby.outQueue.TryDequeue(out responderEnv))
            {
                Assert.Fail();
            }

            Assert.IsTrue(resEndGame.ConversationId == endGame.ConversationId);
            Assert.IsTrue(lobbyAppState.GamesBeingPlayed.Count == 0);
        }
        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();
        }
        public void PassOffFullProtocol()
        {
            //Set up
            //Create the Players
            dummyConversationFactory dumConvoFactPlayer1 = new dummyConversationFactory();
            WaitingRoom    waitingRoom      = new WaitingRoom();
            PlayerAppState player1AppState  = new PlayerAppState(waitingRoom);
            SubSystem      subSystemPlayer1 = new SubSystem(dumConvoFactPlayer1, player1AppState);

            subSystemPlayer1.ProcessID = 3;

            dummyConversationFactory dumConvoFactPlayer2 = new dummyConversationFactory();
            WaitingRoom    waitingRoom2     = new WaitingRoom();
            PlayerAppState player2AppState  = new PlayerAppState(waitingRoom2);
            SubSystem      subSystemPlayer2 = new SubSystem(dumConvoFactPlayer2, player2AppState);

            subSystemPlayer2.ProcessID = 4;

            //Create the GM
            dummyConversationFactory dumConvoFactGM = new dummyConversationFactory();
            GMAppState GMAppState  = new GMAppState();
            SubSystem  subSystemGM = new SubSystem(dumConvoFactGM, GMAppState);

            subSystemGM.ProcessID = 2;

            //Create the Lobby.
            dummyConversationFactory dumConvoFactLobby = new dummyConversationFactory();
            LobbyAppState            lobbyAppState     = new LobbyAppState();
            SubSystem subSystemLobby = new SubSystem(dumConvoFactLobby, lobbyAppState);

            subSystemLobby.ProcessID = 1;

            //Add GM to app state.
            lobbyAppState.addGM(new IPEndPoint(IPAddress.Parse("2.2.2.2"), 2222), new IPEndPoint(IPAddress.Parse("2.2.2.2"), 2221), 2);
            //Add Players to app state.
            lobbyAppState.addPlayer(new IPEndPoint(IPAddress.Parse("3.3.3.3"), 333), 3, "player1");
            lobbyAppState.addPlayer(new IPEndPoint(IPAddress.Parse("4.4.4.4"), 444), 4, "Player2");



            //Execution and Testing.

            //Start the game in the app state.
            short gameIDToStart;

            gameIDToStart = lobbyAppState.startGame();
            //make sure the game started
            Assert.IsTrue(gameIDToStart > 0);

            //Create initiator conversations and set the conversation.
            PassOff passOffLobby = new PassOff();

            passOffLobby.SubSystem      = subSystemLobby;
            passOffLobby.ConversationId = new Identifier(passOffLobby.SubSystem.ProcessID, SubSystem.GetNextSeqNumber());
            passOffLobby.setEPs(gameIDToStart);
            //Note: remote Endpoint set in constructor of passOffLobby.

            //Create Responder conversations
            GameManager.RespondPassOff GMRespondPassOff = new GameManager.RespondPassOff();
            GMRespondPassOff.SubSystem = subSystemGM;
            Player.RespondPassOff Pl1RespondPassOff = new Player.RespondPassOff();
            Pl1RespondPassOff.SubSystem = subSystemPlayer1;
            Player.RespondPassOff Pl2RespondPassOff = new Player.RespondPassOff();
            Pl2RespondPassOff.SubSystem = subSystemPlayer2;


            //Launch conversation.
            passOffLobby.Launch();

            //Wait a weee bit.
            Thread.Sleep(500);


            //------------------ PlayerID from Lobby to GM
            Envelope envPlayerIDFromLobbyToGM = new Envelope(null, null, null, false); //Empty env.
            //The loop below is need to make sure that we are pulling the correct message out of the out queue. Because of the reliablility its possible to get duplicate messages going out.
            int attemptForCorrectMessage = 0;

            while (attemptForCorrectMessage < 6)
            {
                subSystemLobby.outQueue.waitIncomingEnv(3000);
                Thread.Sleep(500);
                if (!subSystemLobby.outQueue.TryDequeue(out envPlayerIDFromLobbyToGM) && envPlayerIDFromLobbyToGM?.Message.GetType() == typeof(PlayerIdMessage))
                {
                    continue; //no message was dequeued or wrong type was dequeued.
                }
                if (envPlayerIDFromLobbyToGM.To.Equals(new IPEndPoint(IPAddress.Parse("2.2.2.2"), 2222)))
                {
                    break; //We got it.
                }
                attemptForCorrectMessage++;
                if (attemptForCorrectMessage >= 6)
                {
                    Assert.Fail();
                }
            }

            //Check the message.
            Assert.AreEqual(new IPEndPoint(IPAddress.Parse("2.2.2.2"), 2222), envPlayerIDFromLobbyToGM.To);

            Envelope tmp;

            //Clear the outgoint queue.
            while (subSystemGM.outQueue.TryDequeue(out tmp))
            {
            }

            //Give the conversation the Message and launch responder conversation.
            GMRespondPassOff.IncomingEnvelope = envPlayerIDFromLobbyToGM;
            GMRespondPassOff.recievedMessagesDict.TryAdd(envPlayerIDFromLobbyToGM.Message.MessageNumber.ToString(), envPlayerIDFromLobbyToGM);
            GMRespondPassOff.Launch();

            //Wait a lil bit.
            Thread.Sleep(1000);

            //------------------ Ack trom GM to Lobby.
            //Get the new env.
            if (!subSystemGM.outQueue.waitIncomingEnv(3000))
            {
                Assert.Fail();
            }
            Thread.Sleep(500);
            Envelope envFromGMToLobbyACK;

            if (!subSystemGM.outQueue.TryDequeue(out envFromGMToLobbyACK))
            {
                Assert.Fail();
            }
            //Check the message
            Assert.IsTrue(envFromGMToLobbyACK.Message.GetType() == typeof(AckMessage));

            //Clear the outgoing queue of lobby.
            while (subSystemLobby.outQueue.TryDequeue(out tmp))
            {
            }

            //Give lobby the envGameIDFromLobbyToPlayer1.
            passOffLobby.Process(envFromGMToLobbyACK);

            //Wait a weee bit
            Thread.Sleep(300);



            //------------------ GameId from Lobby to Player1
            //Get the new env.
            Envelope envGameIDFromLobbyToPlayer1 = new Envelope(null, null, null, false); //Empty env.

            //The loop below is need to make sure that we are pulling the correct message out of the out queue. Because of the reliablility its possible to get duplicate messages going out.
            attemptForCorrectMessage = 0;
            while (attemptForCorrectMessage < 6)
            {
                subSystemLobby.outQueue.waitIncomingEnv(3000);
                Thread.Sleep(500);
                if (!subSystemLobby.outQueue.TryDequeue(out envGameIDFromLobbyToPlayer1) && envGameIDFromLobbyToPlayer1.Message.GetType() == typeof(GameIdMessage))
                {
                    continue; //no message was dequeued, or wrong type of message was dequeued.
                }
                if (envGameIDFromLobbyToPlayer1.To.Equals(new IPEndPoint(IPAddress.Parse("3.3.3.3"), 333)))
                {
                    break; //We got it.
                }
                attemptForCorrectMessage++;
                if (attemptForCorrectMessage == 6)
                {
                    Assert.Fail();
                }
            }

            //Check the message.
            Assert.AreEqual(new IPEndPoint(IPAddress.Parse("3.3.3.3"), 333), envGameIDFromLobbyToPlayer1.To);


            //Clear the outgoint queue.

            while (subSystemPlayer1.outQueue.TryDequeue(out tmp))
            {
            }

            //The the conversation the Message, and launch the conversation.
            Pl1RespondPassOff.IncomingEnvelope = envGameIDFromLobbyToPlayer1;
            Pl1RespondPassOff.recievedMessagesDict.TryAdd(envGameIDFromLobbyToPlayer1.Message.MessageNumber.ToString(), envGameIDFromLobbyToPlayer1);
            Pl1RespondPassOff.Launch();



            //------------------ Ack from Player1 to Lobby.
            //Get the new env.
            if (!subSystemPlayer1.outQueue.waitIncomingEnv(3000))
            {
                Assert.Fail();
            }
            Thread.Sleep(500);
            Envelope envAckFromPl1ToLobby;//Empty env.

            if (!subSystemPlayer1.outQueue.TryDequeue(out envAckFromPl1ToLobby))
            {
                Assert.Fail();
            }

            //Clear the outgoing queue of lobby.
            while (subSystemLobby.outQueue.TryDequeue(out tmp))
            {
            }

            //Give lobby the envGameIDFromLobbyToPlayer1.
            passOffLobby.Process(envAckFromPl1ToLobby);



            //------------------ GameId from Lobby to Player2.
            Envelope envGameIDFromLobbyToPlayer2 = new Envelope(null, null, null, false); //Empty env.

            //The loop below is need to make sure that we are pulling the correct message out of the out queue. Because of the reliablility its possible to get duplicate messages going out.
            attemptForCorrectMessage = 0;
            while (attemptForCorrectMessage < 6)
            {
                subSystemLobby.outQueue.waitIncomingEnv(3000);
                Thread.Sleep(500);
                if (!subSystemLobby.outQueue.TryDequeue(out envGameIDFromLobbyToPlayer2) && envGameIDFromLobbyToPlayer2.Message.GetType() == typeof(GameIdMessage))
                {
                    continue; //no message was dequeued or wrong type was dequeued.
                }
                if (envGameIDFromLobbyToPlayer2.To.Equals(new IPEndPoint(IPAddress.Parse("4.4.4.4"), 444)))
                {
                    break; //We got it.
                }
                attemptForCorrectMessage++;
                if (attemptForCorrectMessage == 6)
                {
                    Assert.Fail();
                }
            }

            //Check the message.
            Assert.AreEqual(new IPEndPoint(IPAddress.Parse("4.4.4.4"), 444), envGameIDFromLobbyToPlayer2.To);

            //Clear the outgoint queue.
            while (subSystemPlayer2.outQueue.TryDequeue(out tmp))
            {
            }

            //The the conversation the Message.
            Pl2RespondPassOff.IncomingEnvelope = envGameIDFromLobbyToPlayer2;
            Pl2RespondPassOff.recievedMessagesDict.TryAdd(envGameIDFromLobbyToPlayer2.Message.MessageNumber.ToString(), envGameIDFromLobbyToPlayer2);
            Pl2RespondPassOff.Launch();



            //------------------  Ack from Player2 to Lobby.
            //Get the new env.
            if (!subSystemPlayer2.outQueue.waitIncomingEnv(3000))
            {
                Assert.Fail();
            }
            Thread.Sleep(500);
            Envelope envAckFromPl2ToLobby;//Empty env.

            if (!subSystemPlayer2.outQueue.TryDequeue(out envAckFromPl2ToLobby))
            {
                Assert.Fail();
            }

            //Clear the outgoing queue of lobby.
            while (subSystemLobby.outQueue.TryDequeue(out tmp))
            {
            }

            //Give lobby the envGameIDFromLobbyToPlayer1.
            passOffLobby.Process(envAckFromPl2ToLobby);

            //------------------ Make sure all the EndPoints are set correctly.
            Assert.AreEqual(player1AppState.GMEndPoint, new IPEndPoint(IPAddress.Parse("2.2.2.2"), 2221));
            Assert.AreEqual(player2AppState.GMEndPoint, new IPEndPoint(IPAddress.Parse("2.2.2.2"), 2221));

            Assert.AreEqual(GMAppState.P1EndPoint, new IPEndPoint(IPAddress.Parse("3.3.3.3"), 333));
            Assert.AreEqual(GMAppState.P2EndPoint, new IPEndPoint(IPAddress.Parse("4.4.4.4"), 444));
        }