public void GetPlaceholderInformationHandlerCancelledDuringAsyncCallback() { 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, new MockBlobSizes(), gvflt: mockGvFlt, gitIndexProjection: gitIndexProjection, reliableBackgroundOperations: new MockReliableBackgroundOperations()); string error; callbacks.TryStart(out error).ShouldEqual(true); gitIndexProjection.BlockGetProjectedFileInfo(willWaitForRequest: true); mockGvFlt.OnGetPlaceholderInformation(1, "test.txt", 0, 0, 0, 0, 1, "UnitTests").ShouldEqual(HResult.Pending); gitIndexProjection.WaitForGetProjectedFileInfo(); mockGvFlt.OnCancelCommand(1); gitIndexProjection.UnblockGetProjectedFileInfo(); // Cancelling in the middle of GetPlaceholderInformation still allows it to create placeholders when the cancellation does not // interrupt network requests mockGvFlt.WaitForPlaceholderCreate(); gitIndexProjection.WaitForPlaceholderCreate(); mockGvFlt.CreatedPlaceholders.ShouldContain(entry => entry == "test.txt"); gitIndexProjection.PlaceholdersCreated.ShouldContain(entry => entry == "test.txt"); callbacks.Stop(); } }
public void GetPlaceholderInformationHandlerCancelledBeforeSchedulingAsync() { 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, new MockBlobSizes(), gvflt: mockGvFlt, gitIndexProjection: gitIndexProjection, reliableBackgroundOperations: new MockReliableBackgroundOperations()); string error; callbacks.TryStart(out error).ShouldEqual(true); gitIndexProjection.BlockIsPathProjected(willWaitForRequest: true); Task.Run(() => { // Wait for OnGetPlaceholderInformation to call IsPathProjected and then while it's blocked there // call OnCancelCommand gitIndexProjection.WaitForIsPathProjected(); mockGvFlt.OnCancelCommand(1); gitIndexProjection.UnblockIsPathProjected(); }); mockGvFlt.OnGetPlaceholderInformation(1, "test.txt", 0, 0, 0, 0, 1, "UnitTests").ShouldEqual(HResult.Pending); // Cancelling before GetPlaceholderInformation has registered the command results in placeholders being created mockGvFlt.WaitForPlaceholderCreate(); gitIndexProjection.WaitForPlaceholderCreate(); mockGvFlt.CreatedPlaceholders.ShouldContain(entry => entry == "test.txt"); gitIndexProjection.PlaceholdersCreated.ShouldContain(entry => entry == "test.txt"); callbacks.Stop(); } }