public async Task TestGameletRunningStopReturnsTrueAsync()
        {
            _gamelet1.State = GameletState.InUse;

            var stoppedGamelet = _gamelet1.Clone();

            stoppedGamelet.State = GameletState.Reserved;
            _gameletClient.GetGameletByNameAsync(_gamelet1.Name)
            .Returns(Task.FromResult(stoppedGamelet));
            _dialogUtil.ShowYesNo(Arg.Any <string>(), Arg.Any <string>()).Returns(true);

            Gamelet gamelet;
            var     result = _gameletSelector.TrySelectAndPrepareGamelet(_targetPath, _deploy,
                                                                         new List <Gamelet> {
                _gamelet1
            }, null, _devAccount, out gamelet);

            Assert.That(result, Is.True);
            Assert.That(gamelet.Id, Is.EqualTo(_gamelet1.Id));
            Assert.That(gamelet.State, Is.EqualTo(GameletState.Reserved));
            await _gameletClient.Received(1).StopGameAsync(_gamelet1.Id);

            AssertMetricRecorded(DeveloperEventType.Types.Type.VsiGameletsSelect,
                                 DeveloperEventStatus.Types.Code.Success);
            AssertMetricRecorded(DeveloperEventType.Types.Type.VsiGameletsClearLogs,
                                 DeveloperEventStatus.Types.Code.Success);
        }
예제 #2
0
        bool StopGameIfNeeded(ref Gamelet gamelet)
        {
            IGameletClient gameletClient = _gameletClientFactory.Create(_runner);
            string         gameletName   = gamelet.Name;

            gamelet = _taskContext.Factory.Run(async() =>
                                               await gameletClient.GetGameletByNameAsync(
                                                   gameletName));

            return(gamelet.State != GameletState.InUse || PromptStopGame(ref gamelet));
        }
예제 #3
0
        void SetupGetGameletApi(Gamelet gamelet, params GameletState[] states)
        {
            IEnumerable <Task <Gamelet> > gameletCopies = states.Select(state =>
            {
                Gamelet gameletCopy = gamelet.Clone();
                gameletCopy.State   = state;
                return(Task.FromResult(gameletCopy));
            }).ToList();

            _gameletClient.GetGameletByNameAsync(gamelet.Name)
            .Returns(gameletCopies.First(), gameletCopies.Skip(1).ToArray());
        }
예제 #4
0
        /// <summary>
        /// Stop a gamelet and wait for it to return to the reserved state.
        /// </summary>
        Gamelet StopGamelet(Gamelet gamelet)
        {
            IAction         action   = _actionRecorder.CreateToolAction(ActionType.GameletStop);
            ICancelableTask stopTask =
                _cancelableTaskFactory.Create(TaskMessages.WaitingForGameStop, async(task) => {
                IGameletClient gameletClient =
                    _gameletClientFactory.Create(_runner.Intercept(action));
                try
                {
                    await gameletClient.StopGameAsync(gamelet.Id);
                }
                catch (CloudException e) when((e.InnerException as RpcException)
                                              ?.StatusCode == StatusCode.FailedPrecondition)
                {
                    // FailedPreconditions likely means there is no game session to stop.
                    // For details see (internal).
                    Trace.WriteLine("Potential race condition while stopping game; " +
                                    $"ignoring RPC error: {e.InnerException.Message}");
                }
                while (!task.IsCanceled)
                {
                    gamelet = await gameletClient.GetGameletByNameAsync(gamelet.Name);
                    if (gamelet.State == GameletState.Reserved)
                    {
                        break;
                    }
                    await Task.Delay(1000);
                }
            });

            if (stopTask.RunAndRecord(action))
            {
                return(gamelet);
            }
            return(null);
        }