Example #1
0
        public void WatchGameServer_Event_Subscribes()
        {
            var mockSdk = new AgonesSDK();
            Action <GameServer> expected = (gs) => { };

            mockSdk.isWatchingGameServer = true;
            mockSdk.WatchGameServer(expected);

            var result = mockSdk.GameServerUpdatedCallbacks[0];

            Assert.AreSame(expected, result);
        }
Example #2
0
        public void WatchGameServer_Returns_OK()
        {
            var        mockClient          = new Mock <SDK.SDKClient>();
            var        mockResponseStream  = new Moq.Mock <IAsyncStreamReader <GameServer> >();
            var        mockSdk             = new AgonesSDK();
            var        expectedWatchReturn = new GameServer();
            GameServer actualWatchReturn   = null;
            var        serverStream        = TestCalls.AsyncServerStreamingCall <GameServer>(mockResponseStream.Object, Task.FromResult(new Metadata()), () => Status.DefaultSuccess, () => new Metadata(), () => { });

            mockClient.Setup(m => m.WatchGameServer(It.IsAny <Empty>(), It.IsAny <Metadata>(), It.IsAny <DateTime?>(), It.IsAny <CancellationToken>())).Returns(serverStream);
            mockResponseStream.Setup(m => m.Current).Returns(expectedWatchReturn);
            mockResponseStream.SetupSequence(m => m.MoveNext(It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(true))
            .Returns(Task.FromResult(false));
            mockSdk.client = mockClient.Object;

            mockSdk.WatchGameServer((gs) => { actualWatchReturn = gs; });

            Assert.AreSame(expectedWatchReturn, actualWatchReturn);
        }
Example #3
0
        private async Task RunAsync(CancellationToken ct)
        {
            try
            {
                if (!await _agonesSdk.ConnectAsync().ConfigureAwait(false))
                {
                    Console.WriteLine("Unable to connect to Agones SDK");
                    System.Environment.Exit(1);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                System.Environment.Exit(1);
            }

            var result = await _agonesSdk.ReadyAsync().ConfigureAwait(false);

            if (result.StatusCode != StatusCode.OK)
            {
                Console.WriteLine("Unable to set status to Ready");
                System.Environment.Exit(1);
            }

            _agonesSdk.WatchGameServer((server =>
            {
                switch (server.Status.State)
                {
                case "Allocated":
                    Console.WriteLine("Allocated");
                    if (_checkTask != null && !_checkTask.IsCompleted)
                    {
                        return;
                    }
                    _checkTask = RunCheck(ct);
                    break;

                case "Ready":
                    Console.WriteLine("Ready");
                    break;

                default:
                    break;
                }
            }));

            await _agonesSdk.Alpha().SetPlayerCapacityAsync(100);

            var capacity = await _agonesSdk.Alpha().GetPlayerCapacityAsync();

            Console.WriteLine($"capacity: {capacity}");

            // run health check
            while (true)
            {
                if (ct.IsCancellationRequested)
                {
                    throw new OperationCanceledException();
                }
                await Task.Delay(1000, ct).ConfigureAwait(false);

                var status = await _agonesSdk.HealthAsync().ConfigureAwait(false);

                if (status.StatusCode != StatusCode.OK)
                {
                    Console.WriteLine("Health check failed");
                }
            }
        }