Skip to content

Commit

Permalink
Bug/fix peek definition integration test (#313)
Browse files Browse the repository at this point in the history
* removed race condition in peek definition test

* temporarily disabled peek definition tests

* fixed peek definition connection race condition
  • Loading branch information
Aditya Bist authored Apr 13, 2017
1 parent a1bc1bc commit 6daadcf
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1008,7 +1008,7 @@ private void InvokeOnConnectionActivities(ConnectionInfo connectionInfo, Connect
}

/// <summary>
/// Invokes the fianl on-disconnect activities if the provided DisconnectParams represents the default
/// Invokes the final on-disconnect activities if the provided DisconnectParams represents the default
/// connection or is null - representing that all connections are being disconnected.
/// </summary>
private void InvokeOnDisconnectionActivities(ConnectionInfo connectionInfo)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -700,111 +700,114 @@ public void GetDatabaseWithQueryConnectionTest()
/// <summary>
/// Get Definition for a object with no definition. Expect a error result
/// </summary>
// [Fact]
// public async void GetDefinitionFromChildrenAndParents()
// {
// string queryString = "select * from master.sys.objects";
[Fact]
public async void GetDefinitionFromChildrenAndParents()
{
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 objects
TextDocumentPosition objectDocument = CreateTextDocPositionWithCursor(26, OwnerUri);

// //cursor on sys
// TextDocumentPosition sysDocument = CreateTextDocPositionWithCursor(22, OwnerUri);

// //cursor on master
// TextDocumentPosition masterDocument = CreateTextDocPositionWithCursor(15, OwnerUri);
//cursor on sys
TextDocumentPosition sysDocument = CreateTextDocPositionWithCursor(22, OwnerUri);

// LiveConnectionHelper.TestConnectionResult connectionResult = LiveConnectionHelper.InitLiveConnectionInfo();
// ScriptFile scriptFile = connectionResult.ScriptFile;
// ConnectionInfo connInfo = connectionResult.ConnectionInfo;
//cursor on master
TextDocumentPosition masterDocument = CreateTextDocPositionWithCursor(15, OwnerUri);

// var bindingQueue = new ConnectedBindingQueue();
// bindingQueue.AddConnectionContext(connInfo);
// scriptFile.Contents = queryString;
LiveConnectionHelper.TestConnectionResult connectionResult = LiveConnectionHelper.InitLiveConnectionInfo();
ScriptFile scriptFile = connectionResult.ScriptFile;
ConnectionInfo connInfo = connectionResult.ConnectionInfo;
connInfo.RemoveAllConnections();
var bindingQueue = new ConnectedBindingQueue();
bindingQueue.AddConnectionContext(connInfo);
scriptFile.Contents = queryString;

// var service = new LanguageService();
// service.BindingQueue = bindingQueue;
// await service.UpdateLanguageServiceOnConnection(connectionResult.ConnectionInfo);
// Thread.Sleep(2000);
var service = new LanguageService();
service.BindingQueue = bindingQueue;
await service.UpdateLanguageServiceOnConnection(connectionResult.ConnectionInfo);
Thread.Sleep(2000);

// ScriptParseInfo scriptInfo = new ScriptParseInfo { IsConnected = true };
// scriptInfo.ConnectionKey = bindingQueue.AddConnectionContext(connInfo);
// service.ScriptParseInfoMap.Add(OwnerUri, scriptInfo);
ScriptParseInfo scriptInfo = new ScriptParseInfo { IsConnected = true };
scriptInfo.ConnectionKey = bindingQueue.AddConnectionContext(connInfo);
service.ScriptParseInfoMap.Add(OwnerUri, scriptInfo);

// // When I call the language service
// var objectResult = service.GetDefinition(objectDocument, scriptFile, connInfo);
// var sysResult = service.GetDefinition(sysDocument, scriptFile, connInfo);
// var masterResult = service.GetDefinition(masterDocument, scriptFile, connInfo);
// When I call the language service
var objectResult = service.GetDefinition(objectDocument, scriptFile, connInfo);
var sysResult = service.GetDefinition(sysDocument, scriptFile, connInfo);
var masterResult = service.GetDefinition(masterDocument, scriptFile, connInfo);

// // Then I expect the results to be non-null
// Assert.NotNull(objectResult);
// Assert.NotNull(sysResult);
// Assert.NotNull(masterResult);
// Then I expect the results to be non-null
Assert.NotNull(objectResult);
Assert.NotNull(sysResult);
Assert.NotNull(masterResult);

// // And I expect the all results to be the same
// Assert.True(CompareLocations(objectResult.Locations, sysResult.Locations));
// Assert.True(CompareLocations(objectResult.Locations, masterResult.Locations));
// And I expect the all results to be the same
Assert.True(CompareLocations(objectResult.Locations, sysResult.Locations));
Assert.True(CompareLocations(objectResult.Locations, masterResult.Locations));

// Cleanup(objectResult.Locations);
// Cleanup(sysResult.Locations);
// Cleanup(masterResult.Locations);
// service.ScriptParseInfoMap.Remove(OwnerUri);
// }
Cleanup(objectResult.Locations);
Cleanup(sysResult.Locations);
Cleanup(masterResult.Locations);
service.ScriptParseInfoMap.Remove(OwnerUri);
connInfo.RemoveAllConnections();
}

// [Fact]
// public async void GetDefinitionFromProcedures()
// {
[Fact]
public async void GetDefinitionFromProcedures()
{

// string queryString = "EXEC master.dbo.sp_MSrepl_startup";
string queryString = "EXEC master.dbo.sp_MSrepl_startup";

// // place the cursor on every token
// place the cursor on every token

// //cursor on objects
// TextDocumentPosition fnDocument = CreateTextDocPositionWithCursor(30, TestUri);
//cursor on objects
TextDocumentPosition fnDocument = CreateTextDocPositionWithCursor(30, TestUri);

// //cursor on sys
// TextDocumentPosition dboDocument = CreateTextDocPositionWithCursor(14, TestUri);
//cursor on sys
TextDocumentPosition dboDocument = CreateTextDocPositionWithCursor(14, TestUri);

// //cursor on master
// TextDocumentPosition masterDocument = CreateTextDocPositionWithCursor(10, TestUri);
//cursor on master
TextDocumentPosition masterDocument = CreateTextDocPositionWithCursor(10, TestUri);

// LiveConnectionHelper.TestConnectionResult connectionResult = LiveConnectionHelper.InitLiveConnectionInfo();
// ScriptFile scriptFile = connectionResult.ScriptFile;
// ConnectionInfo connInfo = connectionResult.ConnectionInfo;
// var bindingQueue = new ConnectedBindingQueue();
// bindingQueue.AddConnectionContext(connInfo);
// scriptFile.Contents = queryString;
LiveConnectionHelper.TestConnectionResult connectionResult = LiveConnectionHelper.InitLiveConnectionInfo();
ScriptFile scriptFile = connectionResult.ScriptFile;
ConnectionInfo connInfo = connectionResult.ConnectionInfo;
connInfo.RemoveAllConnections();
var bindingQueue = new ConnectedBindingQueue();
bindingQueue.AddConnectionContext(connInfo);
scriptFile.Contents = queryString;

// var service = new LanguageService();
// service.BindingQueue = bindingQueue;
// await service.UpdateLanguageServiceOnConnection(connectionResult.ConnectionInfo);
// Thread.Sleep(2000);
var service = new LanguageService();
service.BindingQueue = bindingQueue;
await service.UpdateLanguageServiceOnConnection(connectionResult.ConnectionInfo);
Thread.Sleep(2000);

// ScriptParseInfo scriptInfo = new ScriptParseInfo { IsConnected = true };
// scriptInfo.ConnectionKey = bindingQueue.AddConnectionContext(connInfo);
// service.ScriptParseInfoMap.Add(TestUri, scriptInfo);
ScriptParseInfo scriptInfo = new ScriptParseInfo { IsConnected = true };
scriptInfo.ConnectionKey = bindingQueue.AddConnectionContext(connInfo);
service.ScriptParseInfoMap.Add(TestUri, scriptInfo);

// // When I call the language service
// var fnResult = service.GetDefinition(fnDocument, scriptFile, connInfo);
// var sysResult = service.GetDefinition(dboDocument, scriptFile, connInfo);
// var masterResult = service.GetDefinition(masterDocument, scriptFile, connInfo);
// When I call the language service
var fnResult = service.GetDefinition(fnDocument, scriptFile, connInfo);
var sysResult = service.GetDefinition(dboDocument, scriptFile, connInfo);
var masterResult = service.GetDefinition(masterDocument, scriptFile, connInfo);

// // Then I expect the results to be non-null
// Assert.NotNull(fnResult);
// Assert.NotNull(sysResult);
// Assert.NotNull(masterResult);
// 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));
// 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);
// }
Cleanup(fnResult.Locations);
Cleanup(sysResult.Locations);
Cleanup(masterResult.Locations);
service.ScriptParseInfoMap.Remove(TestUri);
connInfo.RemoveAllConnections();
}


/// <summary>
Expand Down Expand Up @@ -863,4 +866,4 @@ private TextDocumentPosition CreateTextDocPositionWithCursor(int column, string
return textDocPos;
}
}
}
}

0 comments on commit 6daadcf

Please sign in to comment.