コード例 #1
0
        public void TestCleanupPlayerCacheAfterLongConnectionBreak()
        {
            if (this.connectPolicy.IsOnline)
            {
                Assert.Ignore("This is an offline test");
            }

            if (string.IsNullOrEmpty(this.Player1))
            {
                Assert.Ignore("this tests requires userId to be set");
            }

            Thread.Sleep(1000);// to finish everything from perv tests

            var connPolicy = (OfflineConnectPolicy)this.connectPolicy;

            var masterServer = (ITestMasterApplication)connPolicy.MasterServer.Application;

            masterServer.ResetStats();

            UnifiedTestClient masterClient1 = null;
            UnifiedTestClient masterClient2 = null;

            try
            {
                var roomName = this.GenerateRandomizedRoomName(MethodBase.GetCurrentMethod().Name);
                masterClient1 = this.CreateGameOnGameServer(this.Player1, roomName, null, 0, true, true, 3, null, null, checkUserOnJoin: true);

                const int waitDelta = 3_000;
                // we initiate connection break and wait untill GSs are moreved from master + waitDelta
                connPolicy.MasterServer.SimulateConnectionBreak((uint)MasterServerSettings.Default.GSContextTTL + waitDelta);

                // wait till game server context will be removed
                Thread.Sleep(MasterServerSettings.Default.GSContextTTL + waitDelta + 1000);

                // join 2nd client on master:
                masterClient2 = this.CreateMasterClientAndAuthenticate(this.Player2);

                // gs is not reconnected yet, so we will not find our player in cache
                masterClient2.FindFriends(new string[] { this.Player1 }, out var onlineStates, out var userStates);

                Assert.That(onlineStates[0], Is.False);

                Thread.Sleep(GameServerSettings.Default.ConnectReytryInterval * 1000);

                // now GS is reconnected and we should be able to find our player online
                masterClient2.FindFriends(new string[] { this.Player1 }, out onlineStates, out userStates);

                Assert.That(onlineStates[0], Is.True);
                Assert.That(userStates[0], Is.EqualTo(roomName));
            }
            finally
            {
                DisposeClients(masterClient1, masterClient2);
                connPolicy.GameServer.Stop();
                connPolicy.GameServer.Start();
                masterServer.ResetStats();
            }
        }