public GameLaunchBeHelper(IGameletClient gameletClient, ILaunchGameParamsConverter launchGameParamsConverter, int pollingTimeoutMs = 120000, int pollDelayMs = 500) { _gameletClient = gameletClient; _launchGameParamsConverter = launchGameParamsConverter; _pollingTimeoutMs = pollingTimeoutMs; _pollDelayMs = pollDelayMs; }
public void Setup() { _cancelable = Substitute.For <ICancelable>(); _action = Substitute.For <IAction>(); _gameletClient = Substitute.For <IGameletClient>(); _paramsConverter = Substitute.For <ILaunchGameParamsConverter>(); _target = new GameLaunchBeHelper(_gameletClient, _paramsConverter, 1000, 100); }
public VsiGameLaunchFactory(IGameletClient gameletClient, CancelableTask.Factory cancelableTaskFactory, IGameLaunchBeHelper gameLaunchBeHelper, ActionRecorder actionRecorder, IDialogUtil dialogUtil) { _gameletClient = gameletClient; _cancelableTaskFactory = cancelableTaskFactory; _gameLaunchBeHelper = gameLaunchBeHelper; _actionRecorder = actionRecorder; _dialogUtil = dialogUtil; }
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)); }
public void Setup() { _gameletClient = Substitute.For <IGameletClient>(); _cancelableTaskFactory = Substitute.For <CancelableTask.Factory>(); _gameLaunchBeHelper = Substitute.For <IGameLaunchBeHelper>(); _metrics = Substitute.For <IMetrics>(); _actionRecorder = Substitute.For <ActionRecorder>(_metrics); _dialogUtil = Substitute.For <IDialogUtil>(); _launcher = Substitute.For <IChromeClientsLauncher>(); _params = new LaunchParams(); _launcher.LaunchParams.Returns(_params); }
public void SetUp() { gameletClient = Substitute.For <IGameletClient>(); gameletClientFactory = Substitute.For <GameletClient.Factory>(); gameletClientFactory.Create(Arg.Any <ICloudRunner>()).Returns(gameletClient); cloudRunner = Substitute.For <ICloudRunner>(); sshKeyLoader = Substitute.For <ISshKeyLoader>(); sshKnownHostsWriter = Substitute.For <ISshKnownHostsWriter>(); remoteCommand = Substitute.For <IRemoteCommand>(); sshManager = new SshManager(gameletClientFactory, cloudRunner, sshKeyLoader, sshKnownHostsWriter, remoteCommand); }
public GameLauncher(IGameletClient gameletClient, IYetiVSIService vsiService, ILaunchGameParamsConverter launchGameParamsConverter, CancelableTask.Factory cancelableTaskFactory, ActionRecorder actionRecorder, IDialogUtil dialogUtil, IVsiGameLaunchFactory vsiLaunchFactory) { _gameletClient = gameletClient; _vsiService = vsiService; _cancelableTaskFactory = cancelableTaskFactory; _actionRecorder = actionRecorder; _launchGameParamsConverter = launchGameParamsConverter; _dialogUtil = dialogUtil; _vsiLaunchFactory = vsiLaunchFactory; }
public VsiGameLaunch(string launchName, bool isDeveloperResumeOfferEnabled, IGameletClient gameletClient, CancelableTask.Factory cancelableTaskFactory, IGameLaunchBeHelper gameLaunchBeHelper, ActionRecorder actionRecorder, IDialogUtil dialogUtil, int pollingTimeoutMs = 120 * 1000, int pollingTimeoutResumeOfferMs = 120 * 60 * 1000, int pollDelayMs = 500) { LaunchName = launchName; _isDeveloperResumeOfferEnabled = isDeveloperResumeOfferEnabled; _gameletClient = gameletClient; _cancelableTaskFactory = cancelableTaskFactory; _gameLaunchBeHelper = gameLaunchBeHelper; _actionRecorder = actionRecorder; _dialogUtil = dialogUtil; _pollingTimeoutMs = pollingTimeoutMs; _pollingTimeoutResumeOfferMs = pollingTimeoutResumeOfferMs; _pollDelayMs = pollDelayMs; }
public void SetUp() { _debugPortFactory = Substitute.For <DebugPort.Factory>(); _gameletClient = Substitute.For <IGameletClient>(); var gameletClientFactory = Substitute.For <GameletClient.Factory>(); gameletClientFactory.Create(Arg.Any <ICloudRunner>()).Returns(_gameletClient); _dialogUtil = Substitute.For <IDialogUtil>(); _options = Substitute.For <IExtensionOptions>(); var cancelableTaskRunnerFactory = FakeCancelableTask.CreateFactory(new JoinableTaskContext(), false); _metrics = Substitute.For <IMetrics>(); _metrics.NewDebugSessionId().Returns(_testDebugSessionId); var cloudRunner = Substitute.For <ICloudRunner>(); _portSupplier = new DebugPortSupplier(_debugPortFactory, gameletClientFactory, _options, _dialogUtil, cancelableTaskRunnerFactory, _metrics, cloudRunner, _reserver); }
public void Setup() { _cancelable = Substitute.For <ICancelableTask>(); _action = Substitute.For <IAction>(); _gameletClient = Substitute.For <IGameletClient>(); _paramsConverter = Substitute.For <ILaunchGameParamsConverter>(); _cancelableTaskFactory = Substitute.For <CancelableTask.Factory>(); _yetiVsiService = Substitute.For <IYetiVSIService>(); _metrics = Substitute.For <IMetrics>(); _actionRecorder = Substitute.For <ActionRecorder>(_metrics); _devEvent = SetupCreateLaunchEvent(); _dialogUtil = Substitute.For <IDialogUtil>(); _vsiGameLaunchFactory = Substitute.For <IVsiGameLaunchFactory>(); _vsiGameLaunch = Substitute.For <IVsiGameLaunch>(); _vsiGameLaunchFactory.Create(_gameLaunchName, Arg.Any <bool>()).Returns(_vsiGameLaunch); _vsiGameLaunch.LaunchName.Returns(_gameLaunchName); _vsiGameLaunch.LaunchId.Returns(_gameLaunchId); _target = new GameLauncher(_gameletClient, _yetiVsiService, _paramsConverter, _cancelableTaskFactory, _actionRecorder, _dialogUtil, _vsiGameLaunchFactory); SetupCancelableTask(); }
/// <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); }
public void SetUp() { _gamelet1 = new Gamelet { Id = "test_gamelet1", Name = "test_gamelet_name1", IpAddr = "1.2.3.4", State = GameletState.Reserved, }; _gamelet2 = new Gamelet { Id = "test_gamelet2", Name = "test_gamelet_name2", IpAddr = "1.2.3.5", State = GameletState.Reserved, }; _metrics = Substitute.For <IMetrics>(); _metrics.NewDebugSessionId().Returns(_testDebugSessionId); _dialogUtil = Substitute.For <IDialogUtil>(); var sdkConfigFactory = Substitute.For <SdkConfig.Factory>(); var sdkConfig = new SdkConfig(); sdkConfigFactory.LoadOrDefault().Returns(sdkConfig); var credentialManager = Substitute.For <YetiCommon.ICredentialManager>(); credentialManager.LoadAccount().Returns(_testAccount); _instanceSelectionWindow = Substitute.For <IInstanceSelectionWindow>(); var gameletSelectionWindowFactory = Substitute.For <InstanceSelectionWindow.Factory>(); gameletSelectionWindowFactory.Create(Arg.Any <List <Gamelet> >()) .Returns(_instanceSelectionWindow); var cloudRunner = new CloudRunner(sdkConfigFactory, credentialManager, new CloudConnection(), new GgpSDKUtil()); CancelableTask.Factory cancelableTaskFactory = FakeCancelableTask.CreateFactory(new JoinableTaskContext(), false); _gameletClient = Substitute.For <IGameletClient>(); var gameletClientFactory = Substitute.For <GameletClient.Factory>(); gameletClientFactory.Create(Arg.Any <ICloudRunner>()).Returns(_gameletClient); _sshManager = Substitute.For <ISshManager>(); _sshManager.EnableSshAsync(_gamelet1, Arg.Any <IAction>()) .Returns(Task.FromResult(true)); _sshManager.EnableSshAsync(_gamelet2, Arg.Any <IAction>()) .Returns(Task.FromResult(true)); _remoteCommand = Substitute.For <IRemoteCommand>(); var debugSessionMetrics = new DebugSessionMetrics(_metrics); debugSessionMetrics.UseNewDebugSessionId(); _actionRecorder = new ActionRecorder(debugSessionMetrics); _gameletSelector = new GameletSelectorLegacyFlow(_dialogUtil, cloudRunner, gameletSelectionWindowFactory, cancelableTaskFactory, gameletClientFactory, _sshManager, _remoteCommand, _actionRecorder); }
public void SetUp() { _targetPath = "/any/old/target/path"; var fileSystem = new MockFileSystem(); fileSystem.AddFile(_targetPath, new MockFileData("")); _outputDirectory = Path.GetTempPath(); _project = Substitute.For <IAsyncProject>(); _project.GetTargetPathAsync().Returns(_targetPath); _project.GetTargetDirectoryAsync().Returns(Path.GetDirectoryName(_targetPath)); _project.GetTargetFileNameAsync().Returns(Path.GetFileName(_targetPath)); _project.GetOutputDirectoryAsync().Returns(_outputDirectory); _project.GetAbsoluteRootPathAsync().Returns(_testProjectDir); _project.GetApplicationAsync().Returns(_testApplicationName); _project.GetQueryParamsAsync().Returns(_customQueryParams); var sdkConfigFactory = Substitute.For <SdkConfig.Factory>(); var sdkConfig = new SdkConfig(); sdkConfig.OrganizationId = _testOrganizationId; sdkConfig.ProjectId = _testProjectId; sdkConfigFactory.LoadOrDefault().Returns(sdkConfig); _gameletClient = Substitute.For <IGameletClient>(); var gameletClientFactory = Substitute.For <GameletClient.Factory>(); gameletClientFactory.Create(Arg.Any <ICloudRunner>()).Returns(_gameletClient); var remoteCommand = Substitute.For <IRemoteCommand>(); _remoteDeploy = Substitute.For <IRemoteDeploy>(); _dialogUtil = Substitute.For <IDialogUtil>(); var credentialManager = Substitute.For <YetiCommon.ICredentialManager>(); credentialManager.LoadAccount().Returns(_testAccount); var cancelableTaskFactory = FakeCancelableTask.CreateFactory(new JoinableTaskContext(), false); _applicationClient = Substitute.For <IApplicationClient>(); var application = new Application { Id = _testApplicationId, Name = _testApplicationName }; _applicationClient.LoadByNameOrIdAsync(_testApplicationName) .Returns(Task.FromResult(application)); var applicationClientFactory = Substitute.For <ApplicationClient.Factory>(); applicationClientFactory.Create(Arg.Any <ICloudRunner>()).Returns(_applicationClient); _testAccountClientFactory = Substitute.For <TestAccountClient.Factory>(); var testAccount = new TestAccount() { Name = $"organizations/{_testOrganizationId}" + $"/projects/{_testProjectId}/testAccounts/{_testTestAccountId}" }; var testAccountClient = Substitute.For <ITestAccountClient>(); testAccountClient .LoadByIdOrGamerTagAsync(_testOrganizationId, _testProjectId, _testTestAccountId) .Returns(new List <TestAccount> { testAccount }); _testAccountClientFactory.Create(Arg.Any <ICloudRunner>()).Returns(testAccountClient); Substitute.For <IExtensionOptions>(); _yetiVsiService = Substitute.For <IYetiVSIService>(); var options = Substitute.For <IExtensionOptions>(); var debuggerOptions = new YetiVSI.DebuggerOptions.DebuggerOptions(); _yetiVsiService.DebuggerOptions.Returns(debuggerOptions); options.LaunchGameApiFlow.Returns(LaunchGameApiFlow.DISABLED); _yetiVsiService.Options.Returns(options); _metrics = Substitute.For <IMetrics>(); _metrics.NewDebugSessionId().Returns(_testDebugSessionId); var debugMetrics = new DebugSessionMetrics(_metrics); var cloudRunner = new CloudRunner(sdkConfigFactory, credentialManager, new CloudConnection(), new GgpSDKUtil()); _gameletSelector = Substitute.For <IGameletSelector>(); _gameletSelectorFactory = Substitute.For <IGameletSelectorFactory>(); _gameletSelectorFactory.Create(Arg.Any <bool>(), Arg.Any <ActionRecorder>()) .Returns(_gameletSelector); var serializer = new JsonUtil(); _launchCommandFormatter = new ChromeClientLaunchCommandFormatter(serializer); _paramsFactory = new YetiVSI.DebugEngine.DebugEngine.Params.Factory(serializer); _gameLauncher = Substitute.For <IGameLauncher>(); _gameLauncher.LaunchGameApiEnabled.Returns(false); _gameLaunch = Substitute.For <IVsiGameLaunch>(); _gameLaunch.LaunchName.Returns("launch_name"); _ggpDebugQueryTarget = new GgpDebugQueryTarget(fileSystem, sdkConfigFactory, gameletClientFactory, applicationClientFactory, cancelableTaskFactory, _dialogUtil, _remoteDeploy, debugMetrics, credentialManager, _testAccountClientFactory, _gameletSelectorFactory, cloudRunner, _sdkVersion, _launchCommandFormatter, _paramsFactory, _yetiVsiService, _gameLauncher); }