private void TestSetup() { this.gitProcess = new MockGitProcess(); // Create enlistment using git process GVFSEnlistment enlistment = new MockGVFSEnlistment(this.gitProcess); PhysicalFileSystem fileSystem = new MockFileSystem(new MockDirectory(enlistment.EnlistmentRoot, null, null)); // Create and return Context this.tracer = new MockTracer(); this.context = new GVFSContext(this.tracer, fileSystem, repository: null, enlistment: enlistment); }
public void TestActiveSpan() { MockTracer mockTracer = new MockTracer(); Assert.Null(mockTracer.ActiveSpan); using (mockTracer.BuildSpan("foo").StartActive(finishSpanOnDispose: true)) { Assert.Equal(mockTracer.ScopeManager.Active.Span, mockTracer.ActiveSpan); } Assert.Null(mockTracer.ActiveSpan); }
public void OnGetFileStreamHandlesHResultHandleResult() { using (WindowsFileSystemVirtualizerTester tester = new WindowsFileSystemVirtualizerTester(this.Repo)) { tester.MockVirtualization.WriteFileReturnResult = HResult.Handle; tester.InvokeGetFileDataCallback(expectedResult: HResult.Pending); HResult result = tester.MockVirtualization.WaitForCompletionStatus(); result.ShouldEqual(tester.MockVirtualization.WriteFileReturnResult); MockTracer mockTracker = this.Repo.Context.Tracer as MockTracer; mockTracker.RelatedErrorEvents.ShouldBeEmpty(); } }
private GVFSGitObjects CreateTestableGVFSGitObjects(MockHttpGitObjects httpObjects, MockFileSystemWithCallbacks fileSystem) { MockTracer tracer = new MockTracer(); GVFSEnlistment enlistment = new GVFSEnlistment(TestEnlistmentRoot, "https://fakeRepoUrl", "fakeGitBinPath", gvfsHooksRoot: null, authentication: null); enlistment.InitializeCachePathsFromKey(TestLocalCacheRoot, TestObjecRoot); GitRepo repo = new GitRepo(tracer, enlistment, fileSystem, () => new MockLibGit2Repo(tracer)); GVFSContext context = new GVFSContext(tracer, fileSystem, repo, enlistment); GVFSGitObjects dut = new GVFSGitObjects(context, httpObjects); return(dut); }
public void TryWaitForDeleteLogsAtSpecifiedInterval() { string path = "mock:\\file.txt"; DeleteTestsFileSystem fileSystem = new DeleteTestsFileSystem(new[] { new KeyValuePair <string, FileAttributes>(path, FileAttributes.ReadOnly) }); fileSystem.DeleteException = new IOException(); MockTracer mockTracer = new MockTracer(); int maxRetries = 10; fileSystem.TryWaitForDelete(mockTracer, path, retryDelayMs: 0, maxRetries: maxRetries, retryLoggingThreshold: 3).ShouldBeFalse(); fileSystem.DeleteFileCallCount.ShouldEqual(maxRetries + 1); mockTracer.RelatedWarningEvents.Count.ShouldEqual(5, "There should be five warning events, the first and last, and the 4th, 7th, and 10th"); mockTracer.RelatedWarningEvents[0].ShouldContain( new[] { "Failed to delete file, retrying ...", "\"failureCount\":1", "IOException" }); mockTracer.RelatedWarningEvents[1].ShouldContain( new[] { "Failed to delete file, retrying ...", "\"failureCount\":4", "IOException" }); mockTracer.RelatedWarningEvents[2].ShouldContain( new[] { "Failed to delete file, retrying ...", "\"failureCount\":7", "IOException" }); mockTracer.RelatedWarningEvents[3].ShouldContain( new[] { "Failed to delete file, retrying ...", "\"failureCount\":10", "IOException" }); mockTracer.RelatedWarningEvents[4].ShouldContain( new[] { "Failed to delete file.", "\"failureCount\":11", "IOException" }); }
public void OnGetFileStreamHandlesTryCopyBlobContentStreamThrowingOperationCanceled() { using (WindowsFileSystemVirtualizerTester tester = new WindowsFileSystemVirtualizerTester(this.Repo)) { MockTracer mockTracker = this.Repo.Context.Tracer as MockTracer; mockTracker.WaitRelatedEventName = "GetFileStreamHandlerAsyncHandler_OperationCancelled"; MockGVFSGitObjects mockGVFSGitObjects = this.Repo.GitObjects as MockGVFSGitObjects; mockGVFSGitObjects.CancelTryCopyBlobContentStream = true; tester.InvokeGetFileDataCallback(expectedResult: HResult.Pending); mockTracker.WaitForRelatedEvent(); } }
public void TryLoadConfigFailsWhenGitFailsToReadConfig() { MockTracer tracer = new MockTracer(); MockGitProcess gitProcess = new MockGitProcess(); gitProcess.SetExpectedCommandResult("config gvfs.max-retries", () => new GitProcess.Result(string.Empty, ReadConfigFailureMessage, GitProcess.Result.GenericFailureCode)); gitProcess.SetExpectedCommandResult("config gvfs.timeout-seconds", () => new GitProcess.Result(string.Empty, ReadConfigFailureMessage, GitProcess.Result.GenericFailureCode)); RetryConfig config; string error; RetryConfig.TryLoadFromGitConfig(tracer, gitProcess, out config, out error).ShouldEqual(false); error.ShouldContain(ReadConfigFailureMessage); }
public void SetUp() { this.upgradeDirectory = GVFSPlatform.Instance.GetDataRootForGVFSComponent(ProductUpgraderInfo.UpgradeDirectoryName); this.expectedNewVersionExistsFilePath = Path.Combine(this.upgradeDirectory, this.expectedNewVersionExistsFileName); this.mockFileSystem = new Mock <PhysicalFileSystem>(); this.mockFileSystem.Setup(fileSystem => fileSystem.WriteAllText(this.expectedNewVersionExistsFilePath, It.IsAny <string>())); this.tracer = new MockTracer(); this.productUpgraderInfo = new ProductUpgraderInfo( this.tracer, this.mockFileSystem.Object); }
public void TryLoadConfigEnforcesMinimumValuesOnTimeout() { MockTracer tracer = new MockTracer(); MockGitProcess gitProcess = new MockGitProcess(); gitProcess.SetExpectedCommandResult("config gvfs.max-retries", () => new GitProcess.Result("3", string.Empty, GitProcess.Result.SuccessCode)); gitProcess.SetExpectedCommandResult("config gvfs.timeout-seconds", () => new GitProcess.Result("-1", string.Empty, GitProcess.Result.SuccessCode)); RetryConfig config; string error; RetryConfig.TryLoadFromGitConfig(tracer, gitProcess, out config, out error).ShouldEqual(false); error.ShouldContain("Invalid value -1 for setting gvfs.timeout-seconds, value must be greater than or equal to 0"); }
public void TestNonStandardReference() { MockTracer tracer = new MockTracer(Propagators.TextMap); MockSpan parent = (MockSpan)tracer.BuildSpan("parent").Start(); MockSpan nextSpan = (MockSpan)tracer.BuildSpan("follows") .AddReference("a_reference", parent.Context) .Start(); Assert.Equal(parent.Context.SpanId, nextSpan.ParentId); Assert.Single(nextSpan.References); Assert.Equal(nextSpan.References[0], new MockSpan.Reference(parent.Context, "a_reference")); }
public void TestStartExplicitTimestamp() { MockTracer tracer = new MockTracer(); DateTimeOffset startTimestamp = FixedStartTimestamp; { tracer.BuildSpan("foo") .WithStartTimestamp(startTimestamp) .Start() .Finish(); } List <MockSpan> finishedSpans = tracer.FinishedSpans(); Assert.Single(finishedSpans); Assert.Equal(startTimestamp, finishedSpans[0].StartTimestamp); }
private void TestSetup() { ITracer tracer = new MockTracer(); this.enlistment = new MockGVFSEnlistment(); // We need to have the EnlistmentRoot and GitObjectsRoot available for jobs to run this.fileSystem = new ReadyFileSystem(new string[] { this.enlistment.EnlistmentRoot, this.enlistment.GitObjectsRoot }); this.context = new GVFSContext(tracer, this.fileSystem, null, this.enlistment); this.gitObjects = new MockPhysicalGitObjects(tracer, this.fileSystem, this.enlistment, null); }
public LoggingTest() { var serviceProvider = new ServiceCollection() .AddLogging() .AddOpenTracingCoreServices(ot => { ot.AddLoggerProvider(); ot.Services.AddSingleton <ITracer, MockTracer>(); }) .BuildServiceProvider(); _loggerFactory = serviceProvider.GetRequiredService <ILoggerFactory>(); _logger = _loggerFactory.CreateLogger("FooLogger"); _tracer = (MockTracer)serviceProvider.GetRequiredService <ITracer>(); }
public void TestFollowFromReference() { MockTracer tracer = new MockTracer(Propagators.TextMap); MockSpan precedent = (MockSpan)tracer.BuildSpan("precedent").Start(); MockSpan followingSpan = (MockSpan)tracer.BuildSpan("follows") .AddReference(References.FollowsFrom, precedent.Context) .Start(); Assert.Equal(precedent.Context.SpanId, followingSpan.ParentId); Assert.Single(followingSpan.References); MockSpan.Reference followsFromRef = followingSpan.References[0]; Assert.Equal(new MockSpan.Reference(precedent.Context, References.FollowsFrom), followsFromRef); }
public void OnGetFileStreamHandlesCancellationDuringWriteAction() { using (WindowsFileSystemVirtualizerTester tester = new WindowsFileSystemVirtualizerTester(this.Repo)) { MockTracer mockTracker = this.Repo.Context.Tracer as MockTracer; mockTracker.WaitRelatedEventName = "GetFileStreamHandlerAsyncHandler_OperationCancelled"; tester.MockVirtualization.BlockCreateWriteBuffer(willWaitForRequest: true); tester.InvokeGetFileDataCallback(expectedResult: HResult.Pending); tester.MockVirtualization.WaitForCreateWriteBuffer(); tester.MockVirtualization.OnCancelCommand(1); tester.MockVirtualization.UnblockCreateWriteBuffer(); mockTracker.WaitForRelatedEvent(); } }
public void GetPlaceholderInformationHandlerCancelledDuringNetworkRequest() { using (WindowsFileSystemVirtualizerTester tester = new WindowsFileSystemVirtualizerTester(this.Repo)) { MockTracer mockTracker = this.Repo.Context.Tracer as MockTracer; mockTracker.WaitRelatedEventName = "GetPlaceholderInformationAsyncHandler_GetProjectedFileInfo_Cancelled"; tester.GitIndexProjection.ThrowOperationCanceledExceptionOnProjectionRequest = true; tester.MockVirtualization.requiredCallbacks.GetPlaceholderInfoCallback(1, "test.txt", TriggeringProcessId, TriggeringProcessImageFileName).ShouldEqual(HResult.Pending); // Cancelling in the middle of GetPlaceholderInformation in the middle of a network request should not result in placeholder // getting created mockTracker.WaitForRelatedEvent(); tester.MockVirtualization.CreatedPlaceholders.ShouldNotContain(entry => entry == "test.txt"); tester.GitIndexProjection.PlaceholdersCreated.ShouldNotContain(entry => entry == "test.txt"); } }
public void TryLoadConfigUsesDefaultValuesWhenEntriesAreBlank() { MockTracer tracer = new MockTracer(); MockGitProcess gitProcess = new MockGitProcess(); gitProcess.SetExpectedCommandResult("config gvfs.max-retries", () => new GitProcess.Result(string.Empty, string.Empty, GitProcess.Result.SuccessCode)); gitProcess.SetExpectedCommandResult("config gvfs.timeout-seconds", () => new GitProcess.Result(string.Empty, string.Empty, GitProcess.Result.SuccessCode)); RetryConfig config; string error; RetryConfig.TryLoadFromGitConfig(tracer, gitProcess, out config, out error).ShouldEqual(true); error.ShouldEqual(string.Empty); config.MaxRetries.ShouldEqual(RetryConfig.DefaultMaxRetries); config.MaxAttempts.ShouldEqual(config.MaxRetries + 1); config.Timeout.ShouldEqual(TimeSpan.FromSeconds(RetryConfig.DefaultTimeoutSeconds)); }
public void OnGetFileStreamHandlesGvWriteFailure() { using (MockVirtualizationInstance mockGvFlt = new MockVirtualizationInstance()) using (MockGitIndexProjection gitIndexProjection = new MockGitIndexProjection(new[] { "test.txt" })) { GVFltCallbacks callbacks = new GVFltCallbacks( this.Repo.Context, this.Repo.GitObjects, RepoMetadata.Instance, blobSizes: null, gvflt: mockGvFlt, gitIndexProjection: gitIndexProjection, reliableBackgroundOperations: new MockReliableBackgroundOperations()); string error; callbacks.TryStart(out error).ShouldEqual(true); Guid enumerationGuid = Guid.NewGuid(); byte[] contentId = GVFltCallbacks.ConvertShaToContentId("0123456789012345678901234567890123456789"); byte[] epochId = GVFltCallbacks.GetEpochId(); uint fileLength = 100; MockGVFSGitObjects mockGVFSGitObjects = this.Repo.GitObjects as MockGVFSGitObjects; mockGVFSGitObjects.FileLength = fileLength; MockTracer mockTracker = this.Repo.Context.Tracer as MockTracer; mockTracker.WaitRelatedEventName = "GVFltGetFileStreamHandlerAsyncHandler_OperationCancelled"; mockGvFlt.WriteFileReturnStatus = NtStatus.InternalError; mockGvFlt.OnGetFileStream( commandId: 1, relativePath: "test.txt", byteOffset: 0, length: fileLength, streamGuid: Guid.NewGuid(), contentId: contentId, epochId: epochId, triggeringProcessId: 2, triggeringProcessImageFileName: "UnitTest").ShouldEqual(NtStatus.Pending); mockGvFlt.WaitForCompletionStatus().ShouldEqual(mockGvFlt.WriteFileReturnStatus); callbacks.Stop(); } }
public void ParsesCaseChangesAsRenames() { MockTracer tracer = new MockTracer(); DiffHelper diffBackwards = new DiffHelper(tracer, new Mock.Common.MockGVFSEnlistment(), new List <string>(), new List <string>(), includeSymLinks: this.IncludeSymLinks); diffBackwards.ParseDiffFile(GetDataPath("caseChange.txt")); diffBackwards.RequiredBlobs.Count.ShouldEqual(2); diffBackwards.FileAddOperations.Sum(list => list.Value.Count).ShouldEqual(2); diffBackwards.FileDeleteOperations.Count.ShouldEqual(0); diffBackwards.TotalFileDeletes.ShouldEqual(2); diffBackwards.DirectoryOperations.ShouldContain(entry => entry.Operation == DiffTreeResult.Operations.Add); diffBackwards.DirectoryOperations.ShouldContain(entry => entry.Operation == DiffTreeResult.Operations.Delete); diffBackwards.TotalDirectoryOperations.ShouldEqual(6); }
public void TestMultiReferencesBaggage() { MockTracer tracer = new MockTracer(Propagators.TextMap); MockSpan parent = (MockSpan)tracer.BuildSpan("parent").Start(); parent.SetBaggageItem("parent", "foo"); MockSpan precedent = (MockSpan)tracer.BuildSpan("precedent").Start(); precedent.SetBaggageItem("precedent", "bar"); MockSpan followingSpan = (MockSpan)tracer.BuildSpan("follows") .AddReference(References.FollowsFrom, precedent.Context) .AsChildOf(parent.Context) .Start(); Assert.Equal("foo", followingSpan.GetBaggageItem("parent")); Assert.Equal("bar", followingSpan.GetBaggageItem("precedent")); }
public void TestStartTimestamp() { MockTracer tracer = new MockTracer(); DateTimeOffset startTimestamp; { ISpanBuilder fooSpan = tracer.BuildSpan("foo"); Thread.Sleep(20); startTimestamp = DateTimeOffset.Now; fooSpan.Start().Finish(); } List <MockSpan> finishedSpans = tracer.FinishedSpans(); Assert.Single(finishedSpans); MockSpan span = finishedSpans[0]; Assert.True(startTimestamp <= span.StartTimestamp); Assert.True(DateTimeOffset.Now >= span.FinishTimestamp); }
public HttpOutInterceptorTest() { _tracer = new MockTracer(); _options = new HttpOutOptions(); _interceptor = new HttpOutInterceptor(new NullLoggerFactory(), _tracer, Options.Create(_options)); // Inner handler for mocking the result _httpHandler = new MockHttpMessageHandler(); // Wrap with DiagnosticsHandler (which is internal :( ) Type type = typeof(HttpClientHandler).Assembly.GetType("System.Net.Http.DiagnosticsHandler"); ConstructorInfo constructor = type.GetConstructors(BindingFlags.Instance | BindingFlags.Public)[0]; HttpMessageHandler diagnosticsHandler = (HttpMessageHandler)constructor.Invoke(new object[] { _httpHandler }); _httpClient = new HttpClient(diagnosticsHandler); _interceptor.Start(); }