예제 #1
0
        public void RecordCancelable_CancelledSubTask()
        {
            var metricActionInnerType = ActionType.GameletSelect;
            var innerEventType        = DeveloperEventType.Types.Type.VsiGameletsSelect;
            var task = FakeCancelableTask.CreateFactory(new JoinableTaskContext(), false)
                       .Create("test", _ =>
            {
                actionRecorder.RecordToolAction(metricActionInnerType,
                                                () => { throw new OperationCanceledException(); });
            });

            Assert.IsFalse(task.RunAndRecord(actionRecorder, MetricActionType));

            logEvent.StatusCode = DeveloperEventStatus.Types.Code.Cancelled;
            metrics.Received(1).RecordEvent(EventType, logEvent);

            logEvent.StatusCode = DeveloperEventStatus.Types.Code.CanceledSubTask;
            metrics.Received(1).RecordEvent(innerEventType, logEvent);

            Received.InOrder(() =>
            {
                timer.Start();
                timer.Start();
                timer.Stop();
                var unused = timer.ElapsedMilliseconds;
                timer.Stop();
                unused = timer.ElapsedMilliseconds;
            });
        }
예제 #2
0
        public override CancelableTask.Factory GetCancelableTaskFactory()
        {
            if (_cancelableTaskFactory == null)
            {
                _cancelableTaskFactory =
                    FakeCancelableTask.CreateFactory(new JoinableTaskContext(), false);
            }

            return(_cancelableTaskFactory);
        }
예제 #3
0
        public void RecordThroughExtension()
        {
            var task = FakeCancelableTask.CreateFactory(new JoinableTaskContext(), false)
                       .Create("test", _ => { });

            task.RunAndRecord(actionRecorder, MetricActionType);

            logEvent.StatusCode = DeveloperEventStatus.Types.Code.Success;
            metrics.Received(1).RecordEvent(EventType, logEvent);
        }
        public override CancelableTask.Factory GetCancelableTaskFactory()
        {
            if (_cancelableTaskFactory == null)
            {
                var taskContext = _serviceManager.GetJoinableTaskContext();
                _cancelableTaskFactory = FakeCancelableTask.CreateFactory(taskContext, false);
            }

            return(_cancelableTaskFactory);
        }
예제 #5
0
        public void RecordCancelable_Error()
        {
            var task = FakeCancelableTask.CreateFactory(new JoinableTaskContext(), false)
                       .Create("test", _ => { throw new TestException("Test"); });

            Assert.Throws <TestException>(() => task.RunAndRecord(actionRecorder, MetricActionType));

            logEvent.StatusCode = DeveloperEventStatus.Types.Code.InternalError;
            metrics.Received(1).RecordEvent(EventType, logEvent);
            AssertTimerUsedCorrectly();
        }
예제 #6
0
        public void RecordCancelable(bool canceled)
        {
            var expectedStatus = !canceled
                ? DeveloperEventStatus.Types.Code.Success
                : DeveloperEventStatus.Types.Code.Cancelled;
            var task = FakeCancelableTask.CreateFactory(new JoinableTaskContext(), canceled)
                       .Create("test", _ => { });

            Assert.AreEqual(!canceled, task.RunAndRecord(actionRecorder, MetricActionType));

            logEvent.StatusCode = expectedStatus;
            metrics.Received(1).RecordEvent(EventType, logEvent);
            AssertTimerUsedCorrectly();
        }
        IDebugPort2 CreateDebugPort(Gamelet gamelet)
        {
            var    processFactory            = Substitute.For <DebugProcess.Factory>();
            var    dialogUtil                = Substitute.For <IDialogUtil>();
            var    sshManager                = Substitute.For <ISshManager>();
            var    processListRequest        = Substitute.For <IProcessListRequest>();
            var    processListRequestFactory = Substitute.For <ProcessListRequest.Factory>();
            string reserverAccount           = "*****@*****.**";

            processListRequestFactory.Create().Returns(processListRequest);
            CancelableTask.Factory cancelableTaskFactory =
                FakeCancelableTask.CreateFactory(new JoinableTaskContext(), false);
            var portFactory = new DebugPort.Factory(processFactory, processListRequestFactory,
                                                    cancelableTaskFactory, dialogUtil, sshManager,
                                                    _metrics, reserverAccount);

            return(portFactory.Create(gamelet, null, "290"));
        }
예제 #8
0
        public void SetUp()
        {
            _processFactory = Substitute.For <DebugProcess.Factory>();
            _dialogUtil     = Substitute.For <IDialogUtil>();
            _sshManager     = Substitute.For <ISshManager>();

            _processListRequest = Substitute.For <IProcessListRequest>();
            var processListRequestFactory = Substitute.For <ProcessListRequest.Factory>();

            processListRequestFactory.Create().Returns(_processListRequest);

            var cancelableTaskFactory =
                FakeCancelableTask.CreateFactory(new JoinableTaskContext(), false);

            _metrics = Substitute.For <IMetrics>();

            _portFactory = new DebugPort.Factory(_processFactory, processListRequestFactory,
                                                 cancelableTaskFactory, _dialogUtil, _sshManager,
                                                 _metrics, _reserverAccount);
            _portSupplier = Substitute.For <IDebugPortSupplier2>();
        }
예제 #9
0
        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);
        }
        DebugSessionLauncher.Factory CreateLauncherFactory(bool stadiaPlatformAvailable,
                                                           PlatformFactoryFakeConnectRecorder
                                                           connectRecorder = null)
        {
            _debuggerFactory =
                new GrpcDebuggerFactoryFake(new TimeSpan(0), stadiaPlatformAvailable);
            _platformFactory = new GrpcPlatformFactoryFake(connectRecorder);
            var taskContext = new JoinableTaskContext();

            _listenerFactory = new GrpcListenerFactoryFake();

            // If stadiaPlatformAvailable is True the DebugSessionLauncher will connect
            // to the platform 'remote-stadia', otherwise it will use 'remote-linux'
            var platformName = stadiaPlatformAvailable
                ? "remote-stadia"
                : "remote-linux";

            _platformFactory.AddFakeProcess(platformName, _gameBinary, 44);
            var exceptionManagerFactory =
                new LldbExceptionManager.Factory(new Dictionary <int, Signal>());
            var connectOptionsFactory       = new GrpcPlatformConnectOptionsFactory();
            var platformShellCommandFactory = new GrpcPlatformShellCommandFactory();

            var childAdapterFactory = new RemoteValueChildAdapter.Factory();
            var varInfoFactory      = new LLDBVariableInformationFactory(childAdapterFactory);

            var taskExecutor = new TaskExecutor(taskContext.Factory);

            var debugCodeContextFactory =
                new DebugCodeContext.Factory(new DebugMemoryContext.Factory());

            var debugDocumentContextFactory = new DebugDocumentContext.Factory();
            var threadsEnumFactory          = new ThreadEnumFactory();
            var moduleEnumFactory           = new ModuleEnumFactory();
            var frameEnumFactory            = new FrameEnumFactory();
            var codeContextEnumFactory      = new CodeContextEnumFactory();

            var lldbModuleUtil   = new LldbModuleUtil();
            var moduleFileFinder = Substitute.For <IModuleFileFinder>();
            var moduleFileLoadRecorderFactory =
                new ModuleFileLoadMetricsRecorder.Factory(lldbModuleUtil, moduleFileFinder);
            var mockBinaryFileUtil     = Substitute.For <IBinaryFileUtil>();
            var lldbShell              = Substitute.For <ILLDBShell>();
            var actionRecorder         = new ActionRecorder(Substitute.For <IMetrics>());
            var symbolSettingsProvider = Substitute.For <ISymbolSettingsProvider>();
            var attachedProgramFactory = new LldbAttachedProgram.Factory(
                taskContext, new DebugEngineHandler.Factory(taskContext), taskExecutor,
                new LldbEventManager.Factory(new BoundBreakpointEnumFactory(), taskContext),
                new DebugProgram.Factory(taskContext,
                                         new DebugDisassemblyStream.Factory(
                                             debugCodeContextFactory, debugDocumentContextFactory),
                                         debugDocumentContextFactory, debugCodeContextFactory,
                                         threadsEnumFactory, moduleEnumFactory,
                                         codeContextEnumFactory),
                new DebugModuleCache.Factory(new SynchronousDispatcher()),
                new DebugModule.Factory(
                    FakeCancelableTask.CreateFactory(new JoinableTaskContext(), false),
                    actionRecorder, moduleFileLoadRecorderFactory, lldbModuleUtil,
                    symbolSettingsProvider),
                new DebugThread.Factory(frameEnumFactory, taskExecutor).Create,
                new DebugStackFrame.Factory(debugDocumentContextFactory,
                                            new ChildrenProvider.Factory(), debugCodeContextFactory,
                                            Substitute.For <DebugExpression.Factory>().Create,
                                            varInfoFactory,
                                            new VariableInformationEnum.Factory(taskExecutor),
                                            new RegisterSetsBuilder.Factory(varInfoFactory),
                                            taskExecutor).Create, lldbShell,
                new LldbBreakpointManager.Factory(taskContext,
                                                  new DebugPendingBreakpoint.Factory(
                                                      taskContext,
                                                      new DebugBoundBreakpoint.Factory(
                                                          debugDocumentContextFactory,
                                                          debugCodeContextFactory,
                                                          new DebugBreakpointResolution.Factory()),
                                                      new BreakpointErrorEnumFactory(),
                                                      new BoundBreakpointEnumFactory()),
                                                  new DebugWatchpoint.Factory(
                                                      taskContext,
                                                      new DebugWatchpointResolution.Factory(),
                                                      new BreakpointErrorEnumFactory(),
                                                      new BoundBreakpointEnumFactory())),
                new SymbolLoader.Factory(lldbModuleUtil, mockBinaryFileUtil, moduleFileFinder),
                new BinaryLoader.Factory(lldbModuleUtil, moduleFileFinder),
                Substitute.For <IModuleFileLoaderFactory>());

            var coreAttachWarningDialog = new CoreAttachWarningDialogUtil(
                taskContext, Substitute.For <IDialogUtil>());

            return(new DebugSessionLauncher.Factory(
                       taskContext, _debuggerFactory, _listenerFactory, _platformFactory,
                       connectOptionsFactory, platformShellCommandFactory, attachedProgramFactory,
                       actionRecorder, moduleFileLoadRecorderFactory, exceptionManagerFactory, _fileSystem,
                       false, moduleFileFinder, new DumpModulesProvider(_fileSystem),
                       new ModuleSearchLogHolder(), symbolSettingsProvider, coreAttachWarningDialog));
        }
        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);
        }
예제 #12
0
        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);
        }