public void LifeCycle_ProgressStateFaulted_ClearsStatusBar() { // Arrange var progressHandler = new StatusBarReanalysisProgressHandler(dummyStatusBar, logger); // 1. Initial request ReportProgress(progressHandler, CancellableJobRunner.RunnerState.Running, 0, 1000); dummyStatusBar.CheckLastCallWasSetupCall(0, 1000); // 2. Progress updates ReportProgress(progressHandler, CancellableJobRunner.RunnerState.Running, 100, 1000); dummyStatusBar.CheckLastCallWasInProgressCall(100, 1000); dummyStatusBar.ProgressCallCount.Should().Be(2); // 3. Report a fault - should cause statusbar cleanup ReportProgress(progressHandler, CancellableJobRunner.RunnerState.Faulted, 100, 1000); dummyStatusBar.CheckLastCallWasCleanup(); dummyStatusBar.ProgressCallCount.Should().Be(3); // 4. Any further notifications should be ignored ReportProgress(progressHandler, CancellableJobRunner.RunnerState.Running, 111, 222); ReportProgress(progressHandler, CancellableJobRunner.RunnerState.Finished, 555, 666); dummyStatusBar.ProgressCallCount.Should().Be(3); // no further calls }
private void OnAnalysisRequested(object sender, AnalysisRequestEventArgs args) { // Handle notification from the single file monitor that the settings file has changed. // Re-analysis could take multiple seconds so it's possible that we'll get another // file change notification before the re-analysis has completed. // If that happens we'll cancel the current re-analysis and start another one. lock (reanalysisLockObject) { reanalysisJob?.Cancel(); reanalysisProgressHandler?.Dispose(); var filteredIssueTrackers = FilterIssuesTrackersByPath(this.issueTrackers, args.FilePaths); var operations = filteredIssueTrackers .Select <IIssueTracker, Action>(it => () => it.RequestAnalysis(args.Options)) .ToArray(); // create a fixed list - the user could close a file before the reanalysis completes which would cause the enumeration to change reanalysisProgressHandler = new StatusBarReanalysisProgressHandler(vsStatusBar, logger); var message = string.Format(CultureInfo.CurrentCulture, Strings.JobRunner_JobDescription_ReaanalyzeDocs, operations.Length); reanalysisJob = CancellableJobRunner.Start(message, operations, reanalysisProgressHandler, logger); } }
public void LifeCycle() { // Arrange var progressHandler = new StatusBarReanalysisProgressHandler(dummyStatusBar, logger); // 1. Initial request ReportProgress(progressHandler, CancellableJobRunner.RunnerState.Running, 0, 2); dummyStatusBar.CheckLastCallWasSetupCall(0, 2); // 2a. Progress updates ReportProgress(progressHandler, CancellableJobRunner.RunnerState.Running, 1, 2); dummyStatusBar.CheckLastCallWasInProgressCall(1, 2); // 2b. Progress updates ReportProgress(progressHandler, CancellableJobRunner.RunnerState.Running, 2, 2); dummyStatusBar.CheckLastCallWasInProgressCall(2, 2); // 3. Finished -> clean up and reset the statusbar ReportProgress(progressHandler, CancellableJobRunner.RunnerState.Finished, 111, 222); dummyStatusBar.CheckLastCallWasCleanup(); dummyStatusBar.ProgressCallCount.Should().Be(4); // 4. Dispose - should be a no-op in this case progressHandler.Dispose(); dummyStatusBar.ProgressCallCount.Should().Be(4); // status bar should not be called since already cleaned up }
public void LifeCycle_ProgressChanged_CriticalException_NotSuppressed() { // Arrange dummyStatusBar.ProgressOperation = () => throw new StackOverflowException("xxx"); var progressHandler = new StatusBarReanalysisProgressHandler(dummyStatusBar, logger); // Act and Assert: exception should not be suppressed dummyStatusBar.ProgressOperation = () => throw new StackOverflowException("xxx"); Action act = () => ReportProgress(progressHandler, CancellableJobRunner.RunnerState.Running, 1, 2); act.Should().Throw <StackOverflowException>().And.Message.Should().Be("xxx"); logger.AssertPartialOutputStringDoesNotExist("xxx"); }
public void LifeCycle_ProgressChanged_NonCriticalException_Suppressed() { // Arrange bool opExecuted = false; dummyStatusBar.ProgressOperation = () => { opExecuted = true; throw new InvalidOperationException("xxx"); }; var progressHandler = new StatusBarReanalysisProgressHandler(dummyStatusBar, logger); // Act and Assert: exception should be suppressed ReportProgress(progressHandler, CancellableJobRunner.RunnerState.Running, 0, 1000); opExecuted.Should().BeTrue(); logger.AssertPartialOutputStringExists("xxx"); }
private void OnAnalysisRequested(object sender, EventArgs e) { // Handle notification from the single file monitor that the settings file has changed. // Re-analysis could take multiple seconds so it's possible that we'll get another // file change notification before the re-analysis has completed. // If that happens we'll cancel the current re-analysis and start another one. lock (reanalysisLockObject) { reanalysisJob?.Cancel(); reanalysisProgressHandler?.Dispose(); var operations = this.issueTrackers .Select <TextBufferIssueTracker, Action>(it => () => it.RequestAnalysis()) .ToArray(); // create a fixed list - the user could close a file before the reanalysis completes which would cause the enumeration to change reanalysisProgressHandler = new StatusBarReanalysisProgressHandler(vsStatusBar, logger); reanalysisJob = CancellableJobRunner.Start(Strings.JobRunner_JobDescription_ReaanalyzeOpenDocs, operations, reanalysisProgressHandler, logger); } }
private void ReportProgress(StatusBarReanalysisProgressHandler handler, CancellableJobRunner.RunnerState runnerState, int completedOperations, int totalOperations) { handler.Report(new CancellableJobRunner.JobRunnerProgress(runnerState, completedOperations, totalOperations)); }