mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-16 18:47:57 -05:00
Fix an issue with queue deadlocks causing test failures (#77)
This commit is contained in:
@@ -7,6 +7,7 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.SqlTools.ServiceLayer.Utility;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
|
namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
|
||||||
{
|
{
|
||||||
@@ -183,6 +184,8 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
IBindingContext bindingContext = GetOrCreateBindingContext(queueItem.Key);
|
IBindingContext bindingContext = GetOrCreateBindingContext(queueItem.Key);
|
||||||
if (bindingContext == null)
|
if (bindingContext == null)
|
||||||
{
|
{
|
||||||
@@ -230,6 +233,14 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
|
|||||||
queueItem.ResultsTask.ContinueWith((obj) => queueItem.ItemProcessed.Set());
|
queueItem.ResultsTask.ContinueWith((obj) => queueItem.ItemProcessed.Set());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
// catch and log any exceptions raised in the binding calls
|
||||||
|
// set item processed to avoid deadlocks
|
||||||
|
Logger.Write(LogLevel.Error, "Binding queue threw exception " + ex.ToString());
|
||||||
|
queueItem.ItemProcessed.Set();
|
||||||
|
}
|
||||||
|
|
||||||
// if a queue processing cancellation was requested then exit the loop
|
// if a queue processing cancellation was requested then exit the loop
|
||||||
if (token.IsCancellationRequested)
|
if (token.IsCancellationRequested)
|
||||||
|
|||||||
@@ -120,5 +120,20 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.LanguageServices
|
|||||||
// verify that send result was called with a completion array
|
// verify that send result was called with a completion array
|
||||||
requestContext.Verify(m => m.SendResult(It.IsAny<CompletionItem[]>()), Times.Once());
|
requestContext.Verify(m => m.SendResult(It.IsAny<CompletionItem[]>()), Times.Once());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test the service initialization code path and verify nothing throws
|
||||||
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
public async void UpdateLanguageServiceOnConnection()
|
||||||
|
{
|
||||||
|
InitializeTestObjects();
|
||||||
|
|
||||||
|
AutoCompleteHelper.WorkspaceServiceInstance = workspaceService.Object;
|
||||||
|
|
||||||
|
ConnectionInfo connInfo = TestObjects.GetTestConnectionInfo();
|
||||||
|
|
||||||
|
await LanguageService.Instance.UpdateLanguageServiceOnConnection(connInfo);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -163,40 +163,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.LanguageServices
|
|||||||
Assert.True(LanguageService.ConnectionServiceInstance == null);
|
Assert.True(LanguageService.ConnectionServiceInstance == null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Test the service initialization code path and verify nothing throws
|
|
||||||
/// </summary>
|
|
||||||
[Fact]
|
|
||||||
public async void UpdateLanguageServiceOnConnection()
|
|
||||||
{
|
|
||||||
string ownerUri = "file://my/sample/file.sql";
|
|
||||||
var connectionService = TestObjects.GetTestConnectionService();
|
|
||||||
var connectionResult =
|
|
||||||
await connectionService
|
|
||||||
.Connect(new ConnectParams()
|
|
||||||
{
|
|
||||||
OwnerUri = ownerUri,
|
|
||||||
Connection = TestObjects.GetTestConnectionDetails()
|
|
||||||
});
|
|
||||||
|
|
||||||
// set up file for returning the query
|
|
||||||
var fileMock = new Mock<ScriptFile>();
|
|
||||||
fileMock.SetupGet(file => file.Contents).Returns(Common.StandardQuery);
|
|
||||||
fileMock.SetupGet(file => file.ClientFilePath).Returns(ownerUri);
|
|
||||||
|
|
||||||
// set up workspace mock
|
|
||||||
var workspaceService = new Mock<WorkspaceService<SqlToolsSettings>>();
|
|
||||||
workspaceService.Setup(service => service.Workspace.GetFile(It.IsAny<string>()))
|
|
||||||
.Returns(fileMock.Object);
|
|
||||||
|
|
||||||
AutoCompleteHelper.WorkspaceServiceInstance = workspaceService.Object;
|
|
||||||
|
|
||||||
ConnectionInfo connInfo = null;
|
|
||||||
connectionService.TryFindConnection(ownerUri, out connInfo);
|
|
||||||
|
|
||||||
await LanguageService.Instance.UpdateLanguageServiceOnConnection(connInfo);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Test the service initialization code path and verify nothing throws
|
/// Test the service initialization code path and verify nothing throws
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -249,11 +249,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
|
|||||||
|
|
||||||
connInfo = Common.CreateTestConnectionInfo(null, false);
|
connInfo = Common.CreateTestConnectionInfo(null, false);
|
||||||
|
|
||||||
var srvConn = GetServerConnection(connInfo);
|
|
||||||
var displayInfoProvider = new MetadataDisplayInfoProvider();
|
|
||||||
var metadataProvider = SmoMetadataProvider.CreateConnectedProvider(srvConn);
|
|
||||||
var binder = BinderProvider.CreateBinder(metadataProvider);
|
|
||||||
|
|
||||||
LanguageService.Instance.ScriptParseInfoMap.Add(textDocument.TextDocument.Uri, new ScriptParseInfo());
|
LanguageService.Instance.ScriptParseInfoMap.Add(textDocument.TextDocument.Uri, new ScriptParseInfo());
|
||||||
|
|
||||||
scriptFile = new ScriptFile {ClientFilePath = textDocument.TextDocument.Uri};
|
scriptFile = new ScriptFile {ClientFilePath = textDocument.TextDocument.Uri};
|
||||||
|
|||||||
Reference in New Issue
Block a user