bool PromptToDeleteLaunch(GgpGrpc.Models.GameLaunch currentGameLaunch,
                                  List <Gamelet> gamelets, Gamelet selectedGamelet,
                                  ActionRecorder actionRecorder,
                                  string testAccount, string devAccount)
        {
            if (currentGameLaunch.GameLaunchState == GameLaunchState.IncompleteLaunch)
            {
                return(true);
            }

            bool   thisInstance = selectedGamelet.Name == currentGameLaunch.GameletName;
            string instanceName = gamelets
                                  .SingleOrDefault(g => g.Name == currentGameLaunch.GameletName)?.DisplayName;
            bool okToStop = actionRecorder.RecordUserAction(ActionType.GameLaunchStopPrompt,
                                                            () => _dialogUtil.ShowYesNo(
                                                                ErrorStrings.LaunchExistsDialogText(
                                                                    thisInstance, instanceName,
                                                                    testAccount, devAccount),
                                                                ErrorStrings.StopRunningGame));

            if (!okToStop)
            {
                // Developer opted to not stop the existing launch.
                // Launch can not proceed.
                return(false);
            }

            return(true);
        }
        // TODO: remove once the backend bug is fixed.
        /// <summary>
        /// Verifies that the current launch is in RunningGame state, otherwise aborts the attach
        /// process by throwing AttachException.
        /// </summary>
        void VerifyGameIsReady(IAction action)
        {
            // Either new launch api is disabled, or we didn't run the game and only have process
            // id to attach to. We don't match the game launch to the remote process id.
            if (_gameLaunch != null)
            {
                GgpGrpc.Models.GameLaunch state =
                    _taskContext.Factory.Run(async() =>
                                             await _gameLaunch.GetLaunchStateAsync(action));
                if (state.GameLaunchState != GameLaunchState.RunningGame)
                {
                    var devEvent = new DeveloperLogEvent
                    {
                        GameLaunchData = new GameLaunchData
                        {
                            LaunchId = _gameLaunch.LaunchId
                        }
                    };
                    string error = ErrorStrings.GameNotRunningDuringAttach;
                    if (state.GameLaunchEnded != null)
                    {
                        devEvent.GameLaunchData.EndReason = (int)state.GameLaunchEnded.EndReason;
                        error = LaunchUtils.GetEndReason(state.GameLaunchEnded, state.GameletName);
                    }

                    action.UpdateEvent(devEvent);

                    throw new GameLaunchAttachException(VSConstants.E_FAIL, error);
                }
            }
        }
        public void LaunchGameAbortsWhenLaunchEndedWhilePollingForPid()
        {
            var runningGame = new GgpGrpc.Models.GameLaunch
            {
                GameLaunchState = GameLaunchState.RunningGame
            };
            var endedGame = new GgpGrpc.Models.GameLaunch
            {
                GameLaunchState = GameLaunchState.GameLaunchEnded,
                GameLaunchEnded = new GameLaunchEnded(EndReason.GameBinaryNotFound)
            };

            _gameLaunch.GetLaunchStateAsync(Arg.Any <IAction>())
            .Returns(Task.FromResult(runningGame), Task.FromResult(endedGame));

            var launcherFactory = CreateLauncherFactory(true);
            var launcher        = launcherFactory.Create(_debugEngine, LaunchOption.LaunchGame, "",
                                                         _gameBinary, _gameBinary, _gameLaunch);

            _platformFactory.AddRunStatuses(false, false);

            Assert.ThrowsAsync <GameLaunchAttachException>(async() => await LaunchAsync(launcher),
                                                           _binaryNotFound);
            CheckLldbListenerStops();
        }
Beispiel #4
0
        public Task <GgpGrpc.Models.GameLaunch> GetGameLaunchStateAsync(string gameLaunchName)
        {
            GgpGrpc.Models.GameLaunch launch = null;
            if (gameLaunchName.EndsWith("current"))
            {
                Gamelet instanceInUse = _instances.Find(i => i.State == GameletState.InUse);
                if (instanceInUse != null)
                {
                    launch = _launchesByInstance[instanceInUse.Name];
                }
            }
            else
            {
                launch = _launchesByInstance.Values.ToList().Find(l => l.Name == gameLaunchName);
            }

            if (launch == null)
            {
                var rpcException =
                    new RpcException(new Status(StatusCode.NotFound,
                                                "no launch with the specified name found"));
                throw new CloudException("error getting launch status", rpcException);
            }

            return(Task.FromResult(launch));
        }
        public async Task GetLaunchStateAsyncTestAsync()
        {
            _target = GetGameLaunch(false);
            var action     = Substitute.For <IAction>();
            var gameLaunch = GetGameLaunch();

            _gameletClient.GetGameLaunchStateAsync(_launchName, action)
            .Returns(Task.FromResult(gameLaunch));

            GgpGrpc.Models.GameLaunch result = await _target.GetLaunchStateAsync(action);

            Assert.That(result, Is.EqualTo(gameLaunch));
        }
        public async Task GetCurrentGameLaunchSuccessAsync()
        {
            _paramsConverter.FullGameLaunchName(null, _testAccount).Returns(_fullLaunchName);
            GgpGrpc.Models.GameLaunch launch =
                GetLaunch(_gameLaunchName, GameLaunchState.ReadyToPlay);
            _gameletClient.GetGameLaunchStateAsync(_fullLaunchName, _action).Returns(launch);

            GgpGrpc.Models.GameLaunch resultLaunch =
                await _target.GetCurrentGameLaunchAsync(_testAccount, _action);

            Assert.That(resultLaunch, Is.EqualTo(launch));
            await AssertActionNotRecordedAsync();
        }
 void SetupDeleteGameLaunch(string gameletName, GameLaunchState?deletedLaunchState,
                            bool success)
 {
     GgpGrpc.Models.GameLaunch gameLaunch = deletedLaunchState.HasValue
         ? new GgpGrpc.Models.GameLaunch
     {
         GameLaunchState = deletedLaunchState.Value,
         GameletName     = gameletName,
         Name            = _launchName
     }
         : null;
     _gameLaunchBeHelper
     .DeleteLaunchAsync(_launchName, Arg.Any <ICancelable>(), Arg.Any <IAction>()).Returns(
         new DeleteLaunchResult(gameLaunch, success));
 }
        public async Task DeleteLaunchCanceledAsync()
        {
            _gameletClient.DeleteGameLaunchAsync(_gameLaunchName, _action).Returns(
                GetLaunch(_gameLaunchName, GameLaunchState.RunningGame));
            GgpGrpc.Models.GameLaunch lastLaunch =
                GetLaunch(_gameLaunchName, GameLaunchState.GameLaunchEnded,
                          EndReason.GameExitedWithSuccessfulCode);
            _gameletClient.GetGameLaunchStateAsync(_gameLaunchName, _action).Returns(
                GetLaunch(_gameLaunchName, GameLaunchState.RunningGame),
                GetLaunch(_gameLaunchName, GameLaunchState.RunningGame), lastLaunch);
            _cancelable.When(c => c.ThrowIfCancellationRequested())
            .Do(callInfo => throw new TaskAbortedException(new Exception()));

            Assert.ThrowsAsync <TaskAbortedException>(
                () => _target.DeleteLaunchAsync(_gameLaunchName, _cancelable, _action));
            await AssertActionNotRecordedAsync();
        }
        public async Task DeleteLaunchSuccessAsync()
        {
            _gameletClient.DeleteGameLaunchAsync(_gameLaunchName, _action).Returns(
                GetLaunch(_gameLaunchName, GameLaunchState.RunningGame));
            GgpGrpc.Models.GameLaunch lastLaunch =
                GetLaunch(_gameLaunchName, GameLaunchState.GameLaunchEnded,
                          EndReason.GameExitedWithSuccessfulCode);
            _gameletClient.GetGameLaunchStateAsync(_gameLaunchName, _action).Returns(
                GetLaunch(_gameLaunchName, GameLaunchState.RunningGame),
                GetLaunch(_gameLaunchName, GameLaunchState.RunningGame), lastLaunch);

            DeleteLaunchResult result =
                await _target.DeleteLaunchAsync(_gameLaunchName, _cancelable, _action);

            Assert.That(result.IsSuccessful, Is.EqualTo(true));
            Assert.That(result.DeletedLaunch, Is.EqualTo(lastLaunch));
            await AssertActionNotRecordedAsync();
        }
Beispiel #10
0
        public async Task <LaunchGameResponse> LaunchGameAsync(LaunchGameRequest launchRequest)
        {
            var instance = await GetGameletByNameAsync(launchRequest.GameletName);

            instance.State = GameletState.InUse;

            var launch = new GgpGrpc.Models.GameLaunch
            {
                GameLaunchState = GameLaunchState.RunningGame,
                GameletName     = launchRequest.GameletName,
                Name            = Guid.NewGuid().ToString()
            };

            _launchesByInstance.Add(launch.GameletName, launch);
            _lastLaunches?.Add(launchRequest);
            return(new LaunchGameResponse {
                GameLaunchName = launch.Name
            });
        }
        public async Task LaunchGamePollsForPidWhenGameIsRunningAsync()
        {
            var launch = new GgpGrpc.Models.GameLaunch
            {
                GameLaunchState = GameLaunchState.RunningGame
            };

            _gameLaunch.GetLaunchStateAsync(Arg.Any <IAction>()).Returns(Task.FromResult(launch));

            var launcherFactory = CreateLauncherFactory(true);
            var launcher        = launcherFactory.Create(_debugEngine, LaunchOption.LaunchGame, "",
                                                         _gameBinary, _gameBinary, _gameLaunch);

            _platformFactory.AddRunStatuses(false, false, true);

            var program = await LaunchAsync(launcher);

            Assert.That(program, Is.Not.Null);
            program.Stop();
        }
Beispiel #12
0
        // Polling statuses until we see RunningGame or GameLaunchEnded. IncompleteLaunch,
        // ReadyToPlay and DelayedLaunch are transitioning states.
        async Task PollForLaunchStatusAsync(ICancelable task, IAction action)
        {
            int maxPollCount = (_isDeveloperResumeOfferEnabled
                ? _pollingTimeoutResumeOfferMs
                : _pollingTimeoutMs) / _pollDelayMs;
            int currentPollCount = 0;
            var devEvent         = new DeveloperLogEvent
            {
                GameLaunchData = new GameLaunchData {
                    LaunchId = LaunchId
                }
            };

            action.UpdateEvent(devEvent);
            while (++currentPollCount <= maxPollCount)
            {
                task.ThrowIfCancellationRequested();
                GgpGrpc.Models.GameLaunch launch = await GetLaunchStateAsync(action);

                if (launch.GameLaunchState == GameLaunchState.RunningGame)
                {
                    return;
                }

                if (launch.GameLaunchState == GameLaunchState.GameLaunchEnded)
                {
                    string error =
                        LaunchUtils.GetEndReason(launch.GameLaunchEnded, launch.GameletName);
                    devEvent.GameLaunchData.EndReason = (int)launch.GameLaunchEnded.EndReason;
                    action.UpdateEvent(devEvent);
                    throw new GameLaunchFailError(error);
                }

                await Task.Delay(_pollDelayMs);
            }

            if (currentPollCount > maxPollCount)
            {
                throw new TimeoutException(ErrorStrings.LaunchEndedTimeout);
            }
        }
        public async Task <DeleteLaunchResult> WaitUntilGameLaunchEndedAsync(
            string gameLaunchName, ICancelable task, IAction action)
        {
            GgpGrpc.Models.GameLaunch launch =
                await _gameletClient.GetGameLaunchStateAsync(gameLaunchName, action);

            int maxPollCount     = _pollingTimeoutMs / _pollDelayMs;
            int currentPollCount = 0;

            while (launch.GameLaunchState != GameLaunchState.GameLaunchEnded &&
                   ++currentPollCount <= maxPollCount)
            {
                task.ThrowIfCancellationRequested();
                await Task.Delay(_pollDelayMs);

                launch = await _gameletClient.GetGameLaunchStateAsync(gameLaunchName, action);
            }

            return(new DeleteLaunchResult(
                       launch, launch.GameLaunchState == GameLaunchState.GameLaunchEnded));
        }
        bool StopGameLaunchIfPresent(TestAccount testAccount,
                                     string devAccount, List <Gamelet> gamelets,
                                     Gamelet selectedGamelet)
        {
            IAction getExistingAction =
                _actionRecorder.CreateToolAction(ActionType.GameLaunchGetExisting);
            ICancelableTask <GgpGrpc.Models.GameLaunch> currentGameLaunchTask =
                _cancelableTaskFactory.Create(TaskMessages.LookingForTheCurrentLaunch,
                                              async task =>
                                              await _gameLaunchBeHelper
                                              .GetCurrentGameLaunchAsync(
                                                  testAccount?.Name, getExistingAction));

            if (!currentGameLaunchTask.RunAndRecord(getExistingAction))
            {
                return(false);
            }

            GgpGrpc.Models.GameLaunch currentGameLaunch = currentGameLaunchTask.Result;
            if (currentGameLaunch == null)
            {
                return(true);
            }

            if (!PromptToDeleteLaunch(currentGameLaunch, gamelets, selectedGamelet, _actionRecorder,
                                      testAccount?.GamerStadiaName, devAccount))
            {
                return(false);
            }

            IAction deleteAction =
                _actionRecorder.CreateToolAction(ActionType.GameLaunchDeleteExisting);
            ICancelableTask <DeleteLaunchResult> stopTask = _cancelableTaskFactory.Create(
                TaskMessages.WaitingForGameStop,
                async task =>
                await _gameLaunchBeHelper.DeleteLaunchAsync(
                    currentGameLaunch.Name, task, deleteAction));

            return(stopTask.RunAndRecord(deleteAction) && stopTask.Result.IsSuccessful);
        }