コード例 #1
0
        public void Setup()
        {
            _gameApplication = InstanceHelper.GetGame(SERVER_PORT);
            _gameApplication.Start();

            //setup client
            _client = new TestClientPeer(_clientLogger, taskSchedulerFactory, serializer);
        }
コード例 #2
0
        public void Setup()
        {
            _gameApplication = InstanceHelper.GetGame(new List <ushort> {
                SERVER_PORT_1, SERVER_PORT_2
            });
            _gameApplication.Start();

            //setup client
            _client1 = new TestClientPeer(_clientLogger, taskSchedulerFactory, serializer);
            _client2 = new TestClientPeer(_clientLogger, taskSchedulerFactory, serializer);
        }
コード例 #3
0
        public void IntegrationTest()
        {
            var isSuccess = false;

            //create 12 clients and connect them to mm
            for (var i = 0; i < CLIENTS_NUMBER_1; i++)
            {
                var client = new TestClientPeer(_clientLogger, taskSchedulerFactory, serializer);
                client.Connect(CLIENT_CONNECTS_TO_IP, SERVER_PORT_MM);
                _clients.Add(client);
                EmptyTask.Wait(WAIT_TIMEOUT);
            }

            //send auth
            _clients.ForEach(c => c.Send <AuthorizationResponse>(new AuthorizationRequest()).Wait());

            //send join matchmaking (with level = 1)
            _clients.ForEach(c => c.Send <EnterMatchMakingResponse>(new EnterMatchMakingRequest(new Dictionary <byte, object> {
                { FakePropertyCodes.PlayerProperties.Level, 1 }
            })).Wait());
            _clients.ForEach(c => c.WaitFor <JoinInfoEvent>(e => e.JoinInfo != null && e.JoinInfo.Status == JoinStatus.RoomIsReady));

            var mmStats = _mmApplication.GetStats();

            Assert.AreEqual(1, mmStats.RegisteredServers.Count);

            //sending leave mathmaking request
            _clients.ForEach(c => c.Send <LeaveMatchMakingResponse>(new LeaveMatchMakingRequest()).Wait());
            _clients.ForEach(c => c.Disconnect());

            mmStats = _mmApplication.GetStats();
            Assert.AreEqual(0, mmStats.TotalPlayers);
            Assert.AreEqual(1, mmStats.RegisteredServers.Count);

            //connect to server
            _clients.ForEach(c => c.Connect(c.GetJoinInfo().ServerIpAddress.ToString(), c.GetJoinInfo().ServerPort));
            var roomId = _clients.First().GetJoinInfo().RoomId;

            EmptyTask.Wait(MM_TICK * 2);
            var stats = _gameApplication.GetStats();

            Assert.AreEqual(CLIENTS_NUMBER_1, stats.PeerCount);
            Assert.AreEqual(1, stats.RoomCount);
            var roomsPeerCount = stats.RoomsPeerCount.First();

            //players did not join room yet
            Assert.AreEqual(roomId, roomsPeerCount.Key);
            Assert.AreEqual(0, roomsPeerCount.Value);

            //authing
            _clients.ForEach(c =>
            {
                var sessionId = Guid.NewGuid();
                c.SessionId   = sessionId;
                c.Send <AuthorizationResponse>(new AuthorizationRequest()
                {
                    SessionId = sessionId
                });
            });
            EmptyTask.Wait(WAIT_TIMEOUT);

            //joining room
            _clients.ForEach(c => c.Send <JoinRoomResponse>(new JoinRoomRequest(roomId, new Dictionary <byte, object>())));
            EmptyTask.Wait(WAIT_TIMEOUT);
            stats          = _gameApplication.GetStats();
            roomsPeerCount = stats.RoomsPeerCount.First();

            //players joined room
            Assert.AreEqual(roomId, roomsPeerCount.Key);
            Assert.AreEqual(CLIENTS_NUMBER_1, roomsPeerCount.Value);

            //activity
            //each client sends 1000 events to others
            _clients.ForEach(c =>
            {
                for (int i = 0; i < EVENTS_SENT; i++)
                {
                    c.SendEvent(new TestRoomEvent(true, 122, 4.668f, new List <int>()));
                }
            });

            EmptyTask.Wait(WAIT_TIMEOUT * 100);

            isSuccess = true;
            _clients.ForEach(c =>
            {
                if (c.CountOf <TestRoomEvent>() != (CLIENTS_NUMBER_1 - 1) * EVENTS_SENT)
                {
                    _clientLogger.Error($"test events {c.CountOf<TestRoomEvent>()}/{(CLIENTS_NUMBER_1 - 1) * EVENTS_SENT}");
                    isSuccess = false;
                }
            });
            Assert.IsTrue(isSuccess);

            //disconnect from server
            _clients.ForEach(c => c.Disconnect());
            EmptyTask.Wait(WAIT_TIMEOUT);
            stats = _gameApplication.GetStats();
            Assert.AreEqual(0, stats.PeerCount);
        }
コード例 #4
0
        private async Task TestBody(int launchIndex, string ip, ushort port, Dictionary <byte, object> mmProperties, Dictionary <byte, object> joinGameProperties)
        {
            var isSuccess = false;

            _clients.Clear();
            //create N clients and connect them to mm
            for (var i = 0; i < CLIENTS_NUMBER_2; i++)
            {
                var client = new TestClientPeer(_clientLogger, taskSchedulerFactory, serializer);
                await client.Connect(ip, port);

                _clients.Add(client);
                EmptyTask.Wait(WAIT_TIMEOUT);
            }

            //send auth
            foreach (var client in _clients)
            {
                await client.Send <AuthorizationResponse>(new AuthorizationRequest());
            }

            //send join matchmaking (with level = 1)
            foreach (var c in _clients)
            {
                await c.Send <EnterMatchMakingResponse>(new EnterMatchMakingRequest(mmProperties));
            }

            EmptyTask.Wait(6000);

            //check joininfo existance
            isSuccess = true;
            int notJoinedCount = 0;
            int joinedCount    = 0;

            foreach (var c in _clients)
            {
                if (c.GetJoinInfo() == null || c.GetJoinInfo().Status != JoinStatus.RoomIsReady)
                {
                    if (c.GetJoinInfo() != null)
                    {
                        _clientLogger.Info($"Checking joinInfo. Status = {c.GetJoinInfo().Status}");
                    }
                    notJoinedCount++;
                    isSuccess = false;
                }
                else
                {
                    if (c.GetJoinInfo() != null)
                    {
                        _clientLogger.Info($"Checking joinInfo. Status = {c.GetJoinInfo().Status}");
                    }
                    joinedCount++;
                }
            }

            Assert.AreEqual(0, notJoinedCount);
            var roomsCount = CLIENTS_NUMBER_2 / TOTAL_PLAYERS_NEEDED_1 + (CLIENTS_NUMBER_2 % TOTAL_PLAYERS_NEEDED_1 > 0 ? 1: 0);

            Assert.AreEqual(CLIENTS_NUMBER_2 - joinedCount, notJoinedCount);

            var mmStats = _mmApplication.GetStats();

            Assert.AreEqual(1, mmStats.RegisteredServers.Count);

            //sending leave mathmaking request
            foreach (var c in _clients)
            {
                await c.Send <LeaveMatchMakingResponse>(new LeaveMatchMakingRequest());
            }
            foreach (var c in _clients)
            {
                c.Disconnect();
            }

            mmStats = _mmApplication.GetStats();
            Assert.AreEqual(0, mmStats.TotalPlayers);
            Assert.AreEqual(1, mmStats.RegisteredServers.Count);


            //connect to server
            foreach (var c in _clients.Where(c =>
                                             c.GetJoinInfo() != null && c.GetJoinInfo().Status == JoinStatus.RoomIsReady))
            {
                await c.Connect(c.GetJoinInfo().ServerIpAddress, c.GetJoinInfo().ServerPort);
            }

            var stats = _gameApplication.GetStats();

            Assert.AreEqual(joinedCount, stats.PeerCount);
            Assert.AreEqual(roomsCount * launchIndex, stats.RoomCount);

            //authing
            foreach (var c in _clients)
            {
                var sessionId = Guid.NewGuid();
                c.SessionId = sessionId;
                await c.Send <AuthorizationResponse>(new AuthorizationRequest { SessionId = sessionId });
            }

            EmptyTask.Wait(WAIT_TIMEOUT);

            //joining room
            foreach (var c in _clients.Where(c => c.GetJoinInfo() != null))
            {
                await c.Send <JoinRoomResponse>(new JoinRoomRequest(c.GetJoinInfo().RoomId, joinGameProperties));
            }
            EmptyTask.Wait(WAIT_TIMEOUT * 2);
            stats = _gameApplication.GetStats();
            Assert.AreEqual(roomsCount * launchIndex, stats.RoomCount);
            Assert.AreEqual(stats.RoomsPeerCount.Count, stats.RoomCount);

            //disconnect from server
            foreach (var c in _clients)
            {
                c.Disconnect();
            }

            EmptyTask.Wait(WAIT_TIMEOUT);
            stats = _gameApplication.GetStats();
            Assert.AreEqual(0, stats.PeerCount);
        }