mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-16 10:58:30 -05:00
fix peek definition integration tests (#330)
* removed race condition in peek definition test * temporarily disabled peek definition tests * fixed peek definition connection race condition * commented out flaky test * reenabled peek definition tests by removing race condition
This commit is contained in:
@@ -698,113 +698,122 @@ GO";
|
|||||||
// Temporily commented out until a fix is pushed.
|
// Temporily commented out until a fix is pushed.
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get Definition for a object with no definition. Expect a error result
|
/// Get Definition for a object by putting the cursor on 3 different
|
||||||
|
/// objects
|
||||||
/// </summary>
|
/// </summary>
|
||||||
// [Fact]
|
[Fact]
|
||||||
// public async void GetDefinitionFromChildrenAndParents()
|
public async void GetDefinitionFromChildrenAndParents()
|
||||||
// {
|
{
|
||||||
// string queryString = "select * from master.sys.objects";
|
string queryString = "select * from master.sys.objects";
|
||||||
|
|
||||||
// // place the cursor on every token
|
// place the cursor on every token
|
||||||
|
|
||||||
// //cursor on objects
|
|
||||||
// TextDocumentPosition objectDocument = CreateTextDocPositionWithCursor(26, OwnerUri);
|
|
||||||
|
|
||||||
// //cursor on sys
|
|
||||||
// TextDocumentPosition sysDocument = CreateTextDocPositionWithCursor(22, OwnerUri);
|
|
||||||
|
|
||||||
// LiveConnectionHelper.TestConnectionResult connectionResult = LiveConnectionHelper.InitLiveConnectionInfo();
|
//cursor on objects
|
||||||
// ScriptFile scriptFile = connectionResult.ScriptFile;
|
TextDocumentPosition objectDocument = CreateTextDocPositionWithCursor(26, OwnerUri);
|
||||||
// ConnectionInfo connInfo = connectionResult.ConnectionInfo;
|
|
||||||
// connInfo.RemoveAllConnections();
|
|
||||||
// var bindingQueue = new ConnectedBindingQueue();
|
|
||||||
// bindingQueue.AddConnectionContext(connInfo);
|
|
||||||
// scriptFile.Contents = queryString;
|
|
||||||
|
|
||||||
// var service = new LanguageService();
|
//cursor on sys
|
||||||
// service.BindingQueue = bindingQueue;
|
TextDocumentPosition sysDocument = CreateTextDocPositionWithCursor(22, OwnerUri);
|
||||||
// await service.UpdateLanguageServiceOnConnection(connectionResult.ConnectionInfo);
|
|
||||||
// Thread.Sleep(2000);
|
|
||||||
|
|
||||||
// ScriptParseInfo scriptInfo = new ScriptParseInfo { IsConnected = true };
|
//cursor on master
|
||||||
// scriptInfo.ConnectionKey = bindingQueue.AddConnectionContext(connInfo);
|
TextDocumentPosition masterDocument = CreateTextDocPositionWithCursor(17, OwnerUri);
|
||||||
// service.ScriptParseInfoMap.Add(OwnerUri, scriptInfo);
|
|
||||||
|
|
||||||
// // When I call the language service
|
LiveConnectionHelper.TestConnectionResult connectionResult = LiveConnectionHelper.InitLiveConnectionInfo(null, OwnerUri);
|
||||||
// var objectResult = service.GetDefinition(objectDocument, scriptFile, connInfo);
|
ScriptFile scriptFile = connectionResult.ScriptFile;
|
||||||
// var sysResult = service.GetDefinition(sysDocument, scriptFile, connInfo);
|
ConnectionInfo connInfo = connectionResult.ConnectionInfo;
|
||||||
// var masterResult = service.GetDefinition(masterDocument, scriptFile, connInfo);
|
connInfo.RemoveAllConnections();
|
||||||
|
var bindingQueue = new ConnectedBindingQueue();
|
||||||
|
bindingQueue.AddConnectionContext(connInfo);
|
||||||
|
scriptFile.Contents = queryString;
|
||||||
|
|
||||||
// // Then I expect the results to be non-null
|
var service = new LanguageService();
|
||||||
// Assert.NotNull(objectResult);
|
service.RemoveScriptParseInfo(OwnerUri);
|
||||||
// Assert.NotNull(sysResult);
|
service.BindingQueue = bindingQueue;
|
||||||
// Assert.NotNull(masterResult);
|
await service.UpdateLanguageServiceOnConnection(connectionResult.ConnectionInfo);
|
||||||
|
Thread.Sleep(2000);
|
||||||
|
|
||||||
// // And I expect the all results to be the same
|
ScriptParseInfo scriptInfo = new ScriptParseInfo { IsConnected = true };
|
||||||
// Assert.True(CompareLocations(objectResult.Locations, sysResult.Locations));
|
service.ParseAndBind(scriptFile, connInfo);
|
||||||
// Assert.True(CompareLocations(objectResult.Locations, masterResult.Locations));
|
scriptInfo.ConnectionKey = bindingQueue.AddConnectionContext(connInfo);
|
||||||
|
service.ScriptParseInfoMap.Add(OwnerUri, scriptInfo);
|
||||||
|
|
||||||
// Cleanup(objectResult.Locations);
|
// When I call the language service
|
||||||
// Cleanup(sysResult.Locations);
|
var objectResult = service.GetDefinition(objectDocument, scriptFile, connInfo);
|
||||||
// Cleanup(masterResult.Locations);
|
var sysResult = service.GetDefinition(sysDocument, scriptFile, connInfo);
|
||||||
// service.ScriptParseInfoMap.Remove(OwnerUri);
|
var masterResult = service.GetDefinition(masterDocument, scriptFile, connInfo);
|
||||||
// connInfo.RemoveAllConnections();
|
|
||||||
// }
|
|
||||||
|
|
||||||
// [Fact]
|
// Then I expect the results to be non-null
|
||||||
// public async void GetDefinitionFromProcedures()
|
Assert.NotNull(objectResult);
|
||||||
// {
|
Assert.NotNull(sysResult);
|
||||||
|
Assert.NotNull(masterResult);
|
||||||
|
|
||||||
// string queryString = "EXEC master.dbo.sp_MSrepl_startup";
|
// And I expect the all results to be the same
|
||||||
|
Assert.True(CompareLocations(objectResult.Locations, sysResult.Locations));
|
||||||
|
Assert.True(CompareLocations(objectResult.Locations, masterResult.Locations));
|
||||||
|
|
||||||
// // place the cursor on every token
|
Cleanup(objectResult.Locations);
|
||||||
|
Cleanup(sysResult.Locations);
|
||||||
|
Cleanup(masterResult.Locations);
|
||||||
|
service.ScriptParseInfoMap.Remove(OwnerUri);
|
||||||
|
connInfo.RemoveAllConnections();
|
||||||
|
}
|
||||||
|
|
||||||
// //cursor on objects
|
[Fact]
|
||||||
// TextDocumentPosition fnDocument = CreateTextDocPositionWithCursor(30, TestUri);
|
public async void GetDefinitionFromProcedures()
|
||||||
|
{
|
||||||
|
|
||||||
// //cursor on sys
|
string queryString = "EXEC master.dbo.sp_MSrepl_startup";
|
||||||
// TextDocumentPosition dboDocument = CreateTextDocPositionWithCursor(14, TestUri);
|
|
||||||
|
|
||||||
// //cursor on master
|
// place the cursor on every token
|
||||||
// TextDocumentPosition masterDocument = CreateTextDocPositionWithCursor(10, TestUri);
|
|
||||||
|
|
||||||
// LiveConnectionHelper.TestConnectionResult connectionResult = LiveConnectionHelper.InitLiveConnectionInfo();
|
//cursor on objects
|
||||||
// ScriptFile scriptFile = connectionResult.ScriptFile;
|
TextDocumentPosition fnDocument = CreateTextDocPositionWithCursor(30, TestUri);
|
||||||
// ConnectionInfo connInfo = connectionResult.ConnectionInfo;
|
|
||||||
// connInfo.RemoveAllConnections();
|
|
||||||
// var bindingQueue = new ConnectedBindingQueue();
|
|
||||||
// bindingQueue.AddConnectionContext(connInfo);
|
|
||||||
// scriptFile.Contents = queryString;
|
|
||||||
|
|
||||||
// var service = new LanguageService();
|
//cursor on sys
|
||||||
// service.BindingQueue = bindingQueue;
|
TextDocumentPosition dboDocument = CreateTextDocPositionWithCursor(14, TestUri);
|
||||||
// await service.UpdateLanguageServiceOnConnection(connectionResult.ConnectionInfo);
|
|
||||||
// Thread.Sleep(2000);
|
|
||||||
|
|
||||||
// ScriptParseInfo scriptInfo = new ScriptParseInfo { IsConnected = true };
|
//cursor on master
|
||||||
// scriptInfo.ConnectionKey = bindingQueue.AddConnectionContext(connInfo);
|
TextDocumentPosition masterDocument = CreateTextDocPositionWithCursor(10, TestUri);
|
||||||
// service.ScriptParseInfoMap.Add(TestUri, scriptInfo);
|
|
||||||
|
|
||||||
// // When I call the language service
|
LiveConnectionHelper.TestConnectionResult connectionResult = LiveConnectionHelper.InitLiveConnectionInfo(null, TestUri);
|
||||||
// var fnResult = service.GetDefinition(fnDocument, scriptFile, connInfo);
|
ScriptFile scriptFile = connectionResult.ScriptFile;
|
||||||
// var sysResult = service.GetDefinition(dboDocument, scriptFile, connInfo);
|
ConnectionInfo connInfo = connectionResult.ConnectionInfo;
|
||||||
// var masterResult = service.GetDefinition(masterDocument, scriptFile, connInfo);
|
connInfo.RemoveAllConnections();
|
||||||
|
var bindingQueue = new ConnectedBindingQueue();
|
||||||
|
bindingQueue.AddConnectionContext(connInfo);
|
||||||
|
scriptFile.Contents = queryString;
|
||||||
|
|
||||||
// // Then I expect the results to be non-null
|
var service = new LanguageService();
|
||||||
// Assert.NotNull(fnResult);
|
service.RemoveScriptParseInfo(OwnerUri);
|
||||||
// Assert.NotNull(sysResult);
|
service.BindingQueue = bindingQueue;
|
||||||
// Assert.NotNull(masterResult);
|
await service.UpdateLanguageServiceOnConnection(connectionResult.ConnectionInfo);
|
||||||
|
Thread.Sleep(2000);
|
||||||
|
|
||||||
// // And I expect the all results to be the same
|
ScriptParseInfo scriptInfo = new ScriptParseInfo { IsConnected = true };
|
||||||
// Assert.True(CompareLocations(fnResult.Locations, sysResult.Locations));
|
service.ParseAndBind(scriptFile, connInfo);
|
||||||
// Assert.True(CompareLocations(fnResult.Locations, masterResult.Locations));
|
scriptInfo.ConnectionKey = bindingQueue.AddConnectionContext(connInfo);
|
||||||
|
service.ScriptParseInfoMap.Add(TestUri, scriptInfo);
|
||||||
|
|
||||||
// Cleanup(fnResult.Locations);
|
// When I call the language service
|
||||||
// Cleanup(sysResult.Locations);
|
var fnResult = service.GetDefinition(fnDocument, scriptFile, connInfo);
|
||||||
// Cleanup(masterResult.Locations);
|
var sysResult = service.GetDefinition(dboDocument, scriptFile, connInfo);
|
||||||
// service.ScriptParseInfoMap.Remove(TestUri);
|
var masterResult = service.GetDefinition(masterDocument, scriptFile, connInfo);
|
||||||
// connInfo.RemoveAllConnections();
|
|
||||||
// }
|
// Then I expect the results to be non-null
|
||||||
|
Assert.NotNull(fnResult);
|
||||||
|
Assert.NotNull(sysResult);
|
||||||
|
Assert.NotNull(masterResult);
|
||||||
|
|
||||||
|
// And I expect the all results to be the same
|
||||||
|
Assert.True(CompareLocations(fnResult.Locations, sysResult.Locations));
|
||||||
|
Assert.True(CompareLocations(fnResult.Locations, masterResult.Locations));
|
||||||
|
|
||||||
|
Cleanup(fnResult.Locations);
|
||||||
|
Cleanup(sysResult.Locations);
|
||||||
|
Cleanup(masterResult.Locations);
|
||||||
|
service.ScriptParseInfoMap.Remove(TestUri);
|
||||||
|
connInfo.RemoveAllConnections();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -16,21 +16,27 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Utility
|
|||||||
{
|
{
|
||||||
public class LiveConnectionHelper
|
public class LiveConnectionHelper
|
||||||
{
|
{
|
||||||
public static string GetTestSqlFile()
|
public static string GetTestSqlFile(string fileName = null)
|
||||||
{
|
{
|
||||||
string filePath = Path.Combine(
|
string filePath = null;
|
||||||
Path.GetDirectoryName(Assembly.GetEntryAssembly().Location),
|
if (string.IsNullOrEmpty(fileName))
|
||||||
"sqltest.sql");
|
{
|
||||||
|
filePath = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "sqltest.sql");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
filePath = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), fileName + ".sql");
|
||||||
|
}
|
||||||
|
|
||||||
if (File.Exists(filePath))
|
if (File.Exists(filePath))
|
||||||
{
|
{
|
||||||
File.Delete(filePath);
|
File.Delete(filePath);
|
||||||
}
|
}
|
||||||
File.WriteAllText(filePath, "SELECT * FROM sys.objects\n");
|
File.WriteAllText(filePath, "SELECT * FROM sys.objects\n");
|
||||||
return filePath;
|
return filePath;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TestConnectionResult InitLiveConnectionInfo(string databaseName = null)
|
public static TestConnectionResult InitLiveConnectionInfo(string databaseName = null, string fileName = null)
|
||||||
{
|
{
|
||||||
string sqlFilePath = GetTestSqlFile();
|
string sqlFilePath = GetTestSqlFile();
|
||||||
ScriptFile scriptFile = TestServiceProvider.Instance.WorkspaceService.Workspace.GetFile(sqlFilePath);
|
ScriptFile scriptFile = TestServiceProvider.Instance.WorkspaceService.Workspace.GetFile(sqlFilePath);
|
||||||
|
|||||||
Reference in New Issue
Block a user