public async Task TrySynchronizeVirtualDocumentAsync_SimultaneousEqualSynchronizationRequests_ReturnsTrue()
        {
            // Arrange
            var synchronizer = new DefaultLSPDocumentSynchronizer(DocumentManager, JoinableTaskContext);

            synchronizer._synchronizationTimeout = TimeSpan.FromMilliseconds(500);
            var originalVirtualDocument = new TestVirtualDocumentSnapshot(VirtualDocumentUri, 123);
            var originalDocument        = new TestLSPDocumentSnapshot(LSPDocumentUri, 124, originalVirtualDocument);

            // Start synchronize
            var synchronizeTask1 = synchronizer.TrySynchronizeVirtualDocumentAsync(originalDocument, originalVirtualDocument, CancellationToken.None);
            var synchronizeTask2 = synchronizer.TrySynchronizeVirtualDocumentAsync(originalDocument, originalVirtualDocument, CancellationToken.None);

            var newVirtualDocument = originalVirtualDocument.Fork(124);
            var newDocument        = originalDocument.Fork(124, newVirtualDocument);
            var args = new LSPDocumentChangeEventArgs(originalDocument, newDocument, LSPDocumentChangeKind.VirtualDocumentChanged);

            // Act
            synchronizer.DocumentManager_Changed(DocumentManager, args);
            var result1 = await synchronizeTask1.ConfigureAwait(false);

            var result2 = await synchronizeTask2.ConfigureAwait(false);

            // Assert
            Assert.True(result1);
            Assert.True(result2);
        }
Example #2
0
        public async Task TrySynchronizeVirtualDocumentAsync_SimultaneousEqualSynchronizationRequests_ReturnsTrue()
        {
            // Arrange
            var(lspDocument, virtualDocument) = CreateDocuments(lspDocumentVersion: 124, virtualDocumentSyncVersion: 123);
            var fileUriProvider = CreateUriProviderFor(VirtualDocumentTextBuffer, virtualDocument.Uri);
            var synchronizer    = new DefaultLSPDocumentSynchronizer(fileUriProvider);

            synchronizer._synchronizationTimeout = TimeSpan.FromMilliseconds(500);
            NotifyLSPDocumentAdded(lspDocument, synchronizer);

            // Act

            // Start synchronization, this will hang until we notify the buffer versions been updated because the above virtual document expects host doc version 123 but the host doc is 124
            var synchronizeTask1 = synchronizer.TrySynchronizeVirtualDocumentAsync(lspDocument.Version, virtualDocument, CancellationToken.None);
            var synchronizeTask2 = synchronizer.TrySynchronizeVirtualDocumentAsync(lspDocument.Version, virtualDocument, CancellationToken.None);

            NotifyBufferVersionUpdated(VirtualDocumentTextBuffer, lspDocument.Version);
            var result1 = await synchronizeTask1.ConfigureAwait(false);

            var result2 = await synchronizeTask2.ConfigureAwait(false);

            // Assert
            Assert.True(result1);
            Assert.True(result2);
        }
Example #3
0
        public async Task TrySynchronizeVirtualDocumentAsync_SimultaneousDifferentSynchronizationRequests_CancelsFirst_ReturnsFalseThenTrue()
        {
            // Arrange
            var(originalLSPDocument, originalVirtualDocument) = CreateDocuments(lspDocumentVersion: 124, virtualDocumentSyncVersion: 123);
            var fileUriProvider = CreateUriProviderFor(VirtualDocumentTextBuffer, originalVirtualDocument.Uri);
            var synchronizer    = new DefaultLSPDocumentSynchronizer(fileUriProvider);

            synchronizer._synchronizationTimeout = TimeSpan.FromMilliseconds(500);
            NotifyLSPDocumentAdded(originalLSPDocument, synchronizer);

            // Act

            // Start synchronization, this will hang until we notify the buffer versions been updated because the above virtual document expects host doc version 123 but the host doc is 124
            var synchronizeTask1 = synchronizer.TrySynchronizeVirtualDocumentAsync(originalLSPDocument.Version, originalVirtualDocument, CancellationToken.None);

            // Start another synchronization that will also hang because 124 != 125. However, this synchronization request is for the same addressable virtual document (same URI)
            // therefore requesting a second synchronization with a different host doc version expectation will cancel the original synchronization request resulting it returning
            // false.
            var(newLSPDocument, newVirtualDocument) = CreateDocuments(lspDocumentVersion: 125, virtualDocumentSyncVersion: 124);
            var synchronizeTask2 = synchronizer.TrySynchronizeVirtualDocumentAsync(newLSPDocument.Version, newVirtualDocument, CancellationToken.None);

            NotifyBufferVersionUpdated(VirtualDocumentTextBuffer, newLSPDocument.Version);
            var result1 = await synchronizeTask1.ConfigureAwait(false);

            var result2 = await synchronizeTask2.ConfigureAwait(false);

            // Assert
            Assert.False(result1);
            Assert.True(result2);
        }
        public async Task TrySynchronizeVirtualDocumentAsync_SynchronizedDocument_ReturnsTrue()
        {
            // Arrange
            var synchronizer    = new DefaultLSPDocumentSynchronizer(DocumentManager, JoinableTaskContext);
            var virtualDocument = new TestVirtualDocumentSnapshot(VirtualDocumentUri, 123);
            var document        = new TestLSPDocumentSnapshot(LSPDocumentUri, 123, virtualDocument);

            // Act
            var result = await synchronizer.TrySynchronizeVirtualDocumentAsync(document, virtualDocument, CancellationToken.None).ConfigureAwait(false);

            // Assert
            Assert.True(result);
        }
Example #5
0
        public async Task TrySynchronizeVirtualDocumentAsync_SynchronizedDocument_ReturnsTrue()
        {
            // Arrange
            var(lspDocument, virtualDocument) = CreateDocuments(lspDocumentVersion: 123, virtualDocumentSyncVersion: 123);
            var fileUriProvider = CreateUriProviderFor(VirtualDocumentTextBuffer, virtualDocument.Uri);
            var synchronizer    = new DefaultLSPDocumentSynchronizer(fileUriProvider);

            NotifyLSPDocumentAdded(lspDocument, synchronizer);
            NotifyBufferVersionUpdated(VirtualDocumentTextBuffer, virtualDocument.HostDocumentSyncVersion.Value);

            // Act
            var result = await synchronizer.TrySynchronizeVirtualDocumentAsync(lspDocument.Version, virtualDocument, CancellationToken.None).ConfigureAwait(false);

            // Assert
            Assert.True(result);
        }
        public async Task TrySynchronizeVirtualDocumentAsync_Timeout_ReturnsFalse()
        {
            // Arrange
            var synchronizer = new DefaultLSPDocumentSynchronizer(DocumentManager, JoinableTaskContext);

            synchronizer._synchronizationTimeout = TimeSpan.FromMilliseconds(10);
            var originalVirtualDocument = new TestVirtualDocumentSnapshot(VirtualDocumentUri, 123);
            var originalDocument        = new TestLSPDocumentSnapshot(LSPDocumentUri, 124, originalVirtualDocument);

            // Start synchronize
            var synchronizeTask = synchronizer.TrySynchronizeVirtualDocumentAsync(originalDocument, originalVirtualDocument, CancellationToken.None);

            // Act
            var result = await synchronizeTask.ConfigureAwait(false);

            // Assert
            Assert.False(result);
        }
Example #7
0
        public async Task TrySynchronizeVirtualDocumentAsync_Timeout_ReturnsFalse()
        {
            // Arrange
            var(lspDocument, virtualDocument) = CreateDocuments(lspDocumentVersion: 123, virtualDocumentSyncVersion: 123);
            var fileUriProvider = CreateUriProviderFor(VirtualDocumentTextBuffer, virtualDocument.Uri);
            var synchronizer    = new DefaultLSPDocumentSynchronizer(fileUriProvider);

            synchronizer._synchronizationTimeout = TimeSpan.FromMilliseconds(10);
            NotifyLSPDocumentAdded(lspDocument, synchronizer);

            // We're not going to notify that the buffer version was updated so the synchronization will wait until a timeout occurs.

            // Act
            var result = await synchronizer.TrySynchronizeVirtualDocumentAsync(lspDocument.Version, virtualDocument, CancellationToken.None).ConfigureAwait(false);

            // Assert
            Assert.False(result);
        }
        public async Task TrySynchronizeVirtualDocumentAsync_SynchronizesAfterUpdate_ReturnsTrue()
        {
            // Arrange
            var synchronizer = new DefaultLSPDocumentSynchronizer(DocumentManager, JoinableTaskContext);

            synchronizer._synchronizationTimeout = TimeSpan.FromMilliseconds(500);
            var originalVirtualDocument = new TestVirtualDocumentSnapshot(VirtualDocumentUri, 123);
            var originalDocument        = new TestLSPDocumentSnapshot(LSPDocumentUri, 124, originalVirtualDocument);

            // Start synchronization, this will hang until we invoke a DocumentManager_Changed event because the above virtual document expects host doc version 123 but the host doc is 124
            var synchronizeTask = synchronizer.TrySynchronizeVirtualDocumentAsync(originalDocument, originalVirtualDocument, CancellationToken.None);

            // Create a virtual and host doc that are synchronized (both at version 124).
            var newVirtualDocument = originalVirtualDocument.Fork(124);
            var newDocument        = originalDocument.Fork(124, newVirtualDocument);
            var args = new LSPDocumentChangeEventArgs(originalDocument, newDocument, LSPDocumentChangeKind.VirtualDocumentChanged);

            // Act
            synchronizer.DocumentManager_Changed(DocumentManager, args);
            var result = await synchronizeTask.ConfigureAwait(false);

            // Assert
            Assert.True(result);
        }
        public async Task TrySynchronizeVirtualDocumentAsync_SimultaneousDifferentSynchronizationRequests_CancelsFirst_ReturnsFalseThenTrue()
        {
            // Arrange
            var synchronizer = new DefaultLSPDocumentSynchronizer(DocumentManager, JoinableTaskContext);

            synchronizer._synchronizationTimeout = TimeSpan.FromMilliseconds(500);
            var originalVirtualDocument = new TestVirtualDocumentSnapshot(VirtualDocumentUri, 123);
            var originalDocument        = new TestLSPDocumentSnapshot(LSPDocumentUri, 124, originalVirtualDocument);

            // Start synchronization that will hang because 123 != 124
            var synchronizeTask1 = synchronizer.TrySynchronizeVirtualDocumentAsync(originalDocument, originalVirtualDocument, CancellationToken.None);

            var newVirtualDocument = originalVirtualDocument.Fork(124);
            var newDocument        = originalDocument.Fork(125, newVirtualDocument);

            // Start another synchronization that will also hang because 124 != 125. However, this synchronization request is for the same addressable virtual document (same URI)
            // therefore requesting a second synchronization with a different host doc version expectation will cancel the original synchronization request resulting it returning
            // false.
            var synchronizeTask2 = synchronizer.TrySynchronizeVirtualDocumentAsync(newDocument, newVirtualDocument, CancellationToken.None);

            var finalVirtualDocument = newVirtualDocument.Fork(125);
            var finalDocument        = newDocument.Fork(125, finalVirtualDocument);

            var args = new LSPDocumentChangeEventArgs(newDocument, finalDocument, LSPDocumentChangeKind.VirtualDocumentChanged);


            // Act
            synchronizer.DocumentManager_Changed(DocumentManager, args);
            var result1 = await synchronizeTask1.ConfigureAwait(false);

            var result2 = await synchronizeTask2.ConfigureAwait(false);

            // Assert
            Assert.False(result1);
            Assert.True(result2);
        }
Example #10
0
        private static void NotifyLSPDocumentAdded(LSPDocumentSnapshot lspDocument, DefaultLSPDocumentSynchronizer synchronizer)
        {
            var args = new LSPDocumentChangeEventArgs(old: null, @new: lspDocument, LSPDocumentChangeKind.Added);

            synchronizer.DocumentManager_Changed(sender: null, args);
        }