mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-21 01:25:42 -05:00
Fix Code Coverage (#151)
This is another large code review. I want to make a few more changes, but since these changes will stand on their own, I'll hold back on making this change set any larger than it already is. Changes in this request: To address Microsoft/vscode-mssql#326, instead of doing taskkill on the service layer when WaitForExit is executed, we now make an educated guess at which service layer was spawned when the test starts and do a Process.Kill on it when we shut down the test. All the perf tests have been moved into a new project. This was done to keep them easily separated from code coverage test runs. At the same time the perf tests were separated into separate classes for logical categorization. This process will likely be repeated on the stress tests. The tests can still easily be ran from Visual Studio Test Explorer To address Microsoft/vscode-mssql#349, a new SelfCleaningFile class was created to allow for easy cleanup of temporary files generated for integration tests via using blocks. Due to some of the refactoring done while moving the perf tests to a new project, the TestBase class had to be switched to more of a helper class style. As such, all tests that use inherit from TestBase now create a TestBase object on start via a using block. This also simplifies the cleanup at the end of the test. * Solution for hanging code coverage runs Code coverage runs would hang in certain scenarios if a test failed before the service process could be spawned. The taskkill command would fail to find the service process. The test would then wait for opencover to exit, but it would not since the service process it had spawned would still be running, causing the test run to hang indefinitely. Solution was to capture the service process after it launched and explicitly kill it when shutting down the test driver. * Setting the test name in the propery in the class and removign the parameter from each method * New project for perf tests * Reworking integration tests to cleanup temp files * Changes as per @llali review comments * Adding copyright notices * Renaming TestBase => TestHelper * Renaming SelfCleaningFile => SelfCleaningTempFile * Removing code that sets TestName property * Fixing compilation error due to removed code
This commit is contained in:
@@ -3,28 +3,13 @@
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.Common;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using Microsoft.SqlTools.ServiceLayer.Connection;
|
||||
using Microsoft.SqlTools.ServiceLayer.Connection.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.Credentials;
|
||||
using Microsoft.SqlTools.ServiceLayer.LanguageServices;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution;
|
||||
using Microsoft.SqlTools.ServiceLayer.SqlContext;
|
||||
using Microsoft.SqlTools.ServiceLayer.Test.QueryExecution;
|
||||
using Microsoft.SqlTools.ServiceLayer.Test.Utility;
|
||||
using Microsoft.SqlTools.ServiceLayer.Workspace;
|
||||
using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts;
|
||||
using Microsoft.SqlTools.Test.Utility;
|
||||
using Moq;
|
||||
using Moq.Protected;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Test.LanguageServices
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Test.LanguageServer
|
||||
{
|
||||
/// <summary>
|
||||
/// Tests for the ServiceHost Language Service tests
|
||||
@@ -145,14 +130,32 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.LanguageServices
|
||||
|
||||
#region "General Language Service tests"
|
||||
|
||||
|
||||
#if LIVE_CONNECTION_TESTS
|
||||
|
||||
private static void GetLiveAutoCompleteTestObjects(
|
||||
out TextDocumentPosition textDocument,
|
||||
out ScriptFile scriptFile,
|
||||
out ConnectionInfo connInfo)
|
||||
{
|
||||
textDocument = new TextDocumentPosition
|
||||
{
|
||||
TextDocument = new TextDocumentIdentifier {Uri = TestObjects.ScriptUri},
|
||||
Position = new Position
|
||||
{
|
||||
Line = 0,
|
||||
Character = 0
|
||||
}
|
||||
};
|
||||
|
||||
connInfo = TestObjects.InitLiveConnectionInfo(out scriptFile);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test the service initialization code path and verify nothing throws
|
||||
/// </summary>
|
||||
// Test is causing failures in build lab..investigating to reenable
|
||||
[Fact]
|
||||
public void ServiceInitiailzation()
|
||||
public void ServiceInitialization()
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -178,8 +181,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.LanguageServices
|
||||
ScriptFile scriptFile;
|
||||
ConnectionInfo connInfo = TestObjects.InitLiveConnectionInfo(out scriptFile);
|
||||
|
||||
ScriptParseInfo scriptInfo = new ScriptParseInfo();
|
||||
scriptInfo.IsConnected = true;
|
||||
ScriptParseInfo scriptInfo = new ScriptParseInfo {IsConnected = true};
|
||||
|
||||
AutoCompleteHelper.PrepopulateCommonMetadata(connInfo, scriptInfo, null);
|
||||
}
|
||||
@@ -193,7 +195,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.LanguageServices
|
||||
TextDocumentPosition textDocument;
|
||||
ConnectionInfo connInfo;
|
||||
ScriptFile scriptFile;
|
||||
Common.GetAutoCompleteTestObjects(out textDocument, out scriptFile, out connInfo);
|
||||
GetLiveAutoCompleteTestObjects(out textDocument, out scriptFile, out connInfo);
|
||||
|
||||
textDocument.Position.Character = 7;
|
||||
scriptFile.Contents = "select ";
|
||||
@@ -209,52 +211,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.LanguageServices
|
||||
|
||||
#endif
|
||||
|
||||
private Hosting.ServiceHost GetTestServiceHost()
|
||||
{
|
||||
// set up the host details and profile paths
|
||||
var hostDetails = new HostDetails("Test Service Host", "SQLToolsService", new Version(1,0));
|
||||
SqlToolsContext context = new SqlToolsContext(hostDetails);
|
||||
|
||||
// Grab the instance of the service host
|
||||
Hosting.ServiceHost host = Hosting.ServiceHost.Instance;
|
||||
|
||||
// Start the service
|
||||
host.Start().Wait();
|
||||
|
||||
return host;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region "Autocomplete Tests"
|
||||
|
||||
/// <summary>
|
||||
/// Creates a mock db command that returns a predefined result set
|
||||
/// </summary>
|
||||
public static DbCommand CreateTestCommand(Dictionary<string, string>[][] data)
|
||||
{
|
||||
var commandMock = new Mock<DbCommand> { CallBase = true };
|
||||
var commandMockSetup = commandMock.Protected()
|
||||
.Setup<DbDataReader>("ExecuteDbDataReader", It.IsAny<CommandBehavior>());
|
||||
|
||||
commandMockSetup.Returns(new TestDbDataReader(data));
|
||||
|
||||
return commandMock.Object;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a mock db connection that returns predefined data when queried for a result set
|
||||
/// </summary>
|
||||
public DbConnection CreateMockDbConnection(Dictionary<string, string>[][] data)
|
||||
{
|
||||
var connectionMock = new Mock<DbConnection> { CallBase = true };
|
||||
connectionMock.Protected()
|
||||
.Setup<DbCommand>("CreateDbCommand")
|
||||
.Returns(CreateTestCommand(data));
|
||||
|
||||
return connectionMock.Object;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user