mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-28 01:25:44 -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:
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
|
||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>7e5968ab-83d7-4738-85a2-416a50f13d2f</ProjectGuid>
|
||||
<RootNamespace>Microsoft.SqlTools.ServiceLayer.PerfTests</RootNamespace>
|
||||
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
|
||||
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
|
||||
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
|
||||
</Project>
|
||||
31
test/Microsoft.SqlTools.ServiceLayer.PerfTests/Program.cs
Normal file
31
test/Microsoft.SqlTools.ServiceLayer.PerfTests/Program.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using System;
|
||||
using Microsoft.SqlTools.ServiceLayer.TestDriver.Driver;
|
||||
using Microsoft.SqlTools.ServiceLayer.TestDriver.Utility;
|
||||
using Microsoft.SqlTools.ServiceLayer.Utility;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.PerfTests
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
internal static int Main(string[] args)
|
||||
{
|
||||
if (args.Length < 1)
|
||||
{
|
||||
Console.WriteLine("Microsoft.SqlTools.ServiceLayer.PerfTests.exe [tests]" + Environment.NewLine +
|
||||
" [tests] is a space-separated list of tests to run." + Environment.NewLine +
|
||||
" They are qualified within the Microsoft.SqlTools.ServiceLayer.TestDriver.PerfTests namespace" + Environment.NewLine +
|
||||
$"Be sure to set the environment variable {ServiceTestDriver.ServiceHostEnvironmentVariable} to the full path of the sqltoolsservice executable.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
Logger.Initialize("testdriver", LogLevel.Verbose);
|
||||
|
||||
return TestRunner.RunTests(args, "Microsoft.SqlTools.ServiceLayer.PerfTests.Tests.").Result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("Microsoft.SqlTools.ServiceLayer.PerfTests")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("7e5968ab-83d7-4738-85a2-416a50f13d2f")]
|
||||
@@ -0,0 +1,76 @@
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.SqlTools.ServiceLayer.TestDriver.Tests;
|
||||
using Microsoft.SqlTools.ServiceLayer.TestDriver.Utility;
|
||||
using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.PerfTests.Tests
|
||||
{
|
||||
public class Common
|
||||
{
|
||||
internal static async Task ExecuteWithTimeout(TestTimer timer, int timeout, Func<Task<bool>> repeatedCode,
|
||||
TimeSpan? delay = null, [CallerMemberName] string testName = "")
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
if (await repeatedCode())
|
||||
{
|
||||
timer.EndAndPrint(testName);
|
||||
break;
|
||||
}
|
||||
if (timer.TotalMilliSecondsUntilNow >= timeout)
|
||||
{
|
||||
Assert.True(false, $"{testName} timed out after {timeout} milliseconds");
|
||||
break;
|
||||
}
|
||||
if (delay.HasValue)
|
||||
{
|
||||
await Task.Delay(delay.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal static async Task<bool> ConnectAsync(TestHelper testHelper, TestServerType serverType, string query, string ownerUri)
|
||||
{
|
||||
testHelper.WriteToFile(ownerUri, query);
|
||||
|
||||
DidOpenTextDocumentNotification openParams = new DidOpenTextDocumentNotification
|
||||
{
|
||||
TextDocument = new TextDocumentItem
|
||||
{
|
||||
Uri = ownerUri,
|
||||
LanguageId = "enu",
|
||||
Version = 1,
|
||||
Text = query
|
||||
}
|
||||
};
|
||||
|
||||
await testHelper.RequestOpenDocumentNotification(openParams);
|
||||
|
||||
Thread.Sleep(500);
|
||||
var connectParams = await testHelper.GetDatabaseConnectionAsync(serverType);
|
||||
bool connected = await testHelper.Connect(ownerUri, connectParams);
|
||||
Assert.True(connected, "Connection is successful");
|
||||
Console.WriteLine($"Connection to {connectParams.Connection.ServerName} is successful");
|
||||
|
||||
return connected;
|
||||
}
|
||||
|
||||
internal static async Task<T> CalculateRunTime<T>(Func<Task<T>> testToRun, [CallerMemberName] string testName = "")
|
||||
{
|
||||
TestTimer timer = new TestTimer();
|
||||
T result = await testToRun();
|
||||
timer.EndAndPrint(testName);
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.SqlTools.ServiceLayer.TestDriver.Scripts;
|
||||
using Microsoft.SqlTools.ServiceLayer.TestDriver.Tests;
|
||||
using Microsoft.SqlTools.ServiceLayer.TestDriver.Utility;
|
||||
using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.PerfTests.Tests
|
||||
{
|
||||
public class ConnectionTests
|
||||
{
|
||||
|
||||
[Fact]
|
||||
public async Task ConnectAzureTest()
|
||||
{
|
||||
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
|
||||
using (TestHelper testHelper = new TestHelper())
|
||||
{
|
||||
const string query = Scripts.SimpleQuery;
|
||||
testHelper.WriteToFile(queryTempFile.FilePath, query);
|
||||
|
||||
DidOpenTextDocumentNotification openParams = new DidOpenTextDocumentNotification
|
||||
{
|
||||
TextDocument = new TextDocumentItem
|
||||
{
|
||||
Uri = queryTempFile.FilePath,
|
||||
LanguageId = "enu",
|
||||
Version = 1,
|
||||
Text = query
|
||||
}
|
||||
};
|
||||
|
||||
await testHelper.RequestOpenDocumentNotification(openParams);
|
||||
|
||||
Thread.Sleep(500);
|
||||
var connected = await Common.CalculateRunTime(async () =>
|
||||
{
|
||||
var connectParams = await testHelper.GetDatabaseConnectionAsync(TestServerType.Azure);
|
||||
return await testHelper.Connect(queryTempFile.FilePath, connectParams);
|
||||
});
|
||||
Assert.True(connected, "Connection was not successful");
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ConnectOnPremTest()
|
||||
{
|
||||
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
|
||||
using (TestHelper testHelper = new TestHelper())
|
||||
{
|
||||
const string query = Scripts.SimpleQuery;
|
||||
testHelper.WriteToFile(queryTempFile.FilePath, query);
|
||||
|
||||
DidOpenTextDocumentNotification openParams = new DidOpenTextDocumentNotification
|
||||
{
|
||||
TextDocument = new TextDocumentItem
|
||||
{
|
||||
Uri = queryTempFile.FilePath,
|
||||
LanguageId = "enu",
|
||||
Version = 1,
|
||||
Text = query
|
||||
}
|
||||
};
|
||||
|
||||
await testHelper.RequestOpenDocumentNotification(openParams);
|
||||
|
||||
Thread.Sleep(500);
|
||||
var connected = await Common.CalculateRunTime(async () =>
|
||||
{
|
||||
var connectParams = await testHelper.GetDatabaseConnectionAsync(TestServerType.OnPrem);
|
||||
return await testHelper.Connect(queryTempFile.FilePath, connectParams);
|
||||
});
|
||||
Assert.True(connected, "Connection was not successful");
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task DisconnectTest()
|
||||
{
|
||||
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
|
||||
using (TestHelper testHelper = new TestHelper())
|
||||
{
|
||||
await Common.ConnectAsync(testHelper, TestServerType.OnPrem, Scripts.SimpleQuery, queryTempFile.FilePath);
|
||||
Thread.Sleep(1000);
|
||||
var connected = await Common.CalculateRunTime(() => testHelper.Disconnect(queryTempFile.FilePath));
|
||||
Assert.True(connected);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,214 @@
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.SqlTools.ServiceLayer.LanguageServices.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.TestDriver.Scripts;
|
||||
using Microsoft.SqlTools.ServiceLayer.TestDriver.Tests;
|
||||
using Microsoft.SqlTools.ServiceLayer.TestDriver.Utility;
|
||||
using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.PerfTests.Tests
|
||||
{
|
||||
public class IntellisenseTests
|
||||
{
|
||||
[Fact]
|
||||
public async Task HoverTestOnPrem()
|
||||
{
|
||||
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
|
||||
using (TestHelper testHelper = new TestHelper())
|
||||
{
|
||||
const string query = Scripts.SimpleQuery;
|
||||
await Common.ConnectAsync(testHelper, TestServerType.OnPrem, query, queryTempFile.FilePath);
|
||||
Hover hover = await Common.CalculateRunTime(() => testHelper.RequestHover(queryTempFile.FilePath, query, 0, 15));
|
||||
Assert.NotNull(hover);
|
||||
await testHelper.Disconnect(queryTempFile.FilePath);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task SuggestionsTest()
|
||||
{
|
||||
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
|
||||
using (TestHelper testHelper = new TestHelper())
|
||||
{
|
||||
const string query = Scripts.SimpleQuery;
|
||||
await Common.ConnectAsync(testHelper, TestServerType.OnPrem, query, queryTempFile.FilePath);
|
||||
await ValidateCompletionResponse(testHelper, queryTempFile.FilePath, query, null);
|
||||
await ValidateCompletionResponse(testHelper, queryTempFile.FilePath, query);
|
||||
await testHelper.Disconnect(queryTempFile.FilePath);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task DiagnosticsTests()
|
||||
{
|
||||
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
|
||||
using (TestHelper testHelper = new TestHelper())
|
||||
{
|
||||
await Common.ConnectAsync(testHelper, TestServerType.OnPrem, Scripts.SimpleQuery, queryTempFile.FilePath);
|
||||
|
||||
Thread.Sleep(500);
|
||||
var contentChanges = new TextDocumentChangeEvent[1];
|
||||
contentChanges[0] = new TextDocumentChangeEvent()
|
||||
{
|
||||
Range = new Range
|
||||
{
|
||||
Start = new Position
|
||||
{
|
||||
Line = 0,
|
||||
Character = 5
|
||||
},
|
||||
End = new Position
|
||||
{
|
||||
Line = 0,
|
||||
Character = 6
|
||||
}
|
||||
},
|
||||
RangeLength = 1,
|
||||
Text = "z"
|
||||
};
|
||||
DidChangeTextDocumentParams changeParams = new DidChangeTextDocumentParams
|
||||
{
|
||||
ContentChanges = contentChanges,
|
||||
TextDocument = new VersionedTextDocumentIdentifier
|
||||
{
|
||||
Version = 2,
|
||||
Uri = queryTempFile.FilePath
|
||||
}
|
||||
};
|
||||
|
||||
TestTimer timer = new TestTimer();
|
||||
await testHelper.RequestChangeTextDocumentNotification(changeParams);
|
||||
await Common.ExecuteWithTimeout(timer, 60000, async () =>
|
||||
{
|
||||
var completeEvent = await testHelper.Driver.WaitForEvent(PublishDiagnosticsNotification.Type, 15000);
|
||||
return completeEvent?.Diagnostics != null && completeEvent.Diagnostics.Length > 0;
|
||||
});
|
||||
await testHelper.Disconnect(queryTempFile.FilePath);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task BindingCacheColdAzureSimpleQuery()
|
||||
{
|
||||
using (TestHelper testHelper = new TestHelper())
|
||||
{
|
||||
await VerifyBindingLoadScenario(testHelper, TestServerType.Azure, Scripts.SimpleQuery);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task BindingCacheColdOnPremSimpleQuery()
|
||||
{
|
||||
using (TestHelper testHelper = new TestHelper())
|
||||
{
|
||||
await VerifyBindingLoadScenario(testHelper, TestServerType.OnPrem, Scripts.SimpleQuery);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task BindingCacheWarmAzureSimpleQuery()
|
||||
{
|
||||
using (TestHelper testHelper = new TestHelper())
|
||||
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
|
||||
{
|
||||
const string query = Scripts.SimpleQuery;
|
||||
const TestServerType serverType = TestServerType.Azure;
|
||||
await Common.ConnectAsync(testHelper, serverType, query, queryTempFile.FilePath);
|
||||
Thread.Sleep(10000);
|
||||
await VerifyBindingLoadScenario(testHelper, serverType, query);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task BindingCacheWarmOnPremSimpleQuery()
|
||||
{
|
||||
using (TestHelper testHelper = new TestHelper())
|
||||
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
|
||||
{
|
||||
const string query = Scripts.SimpleQuery;
|
||||
const TestServerType serverType = TestServerType.OnPrem;
|
||||
await Common.ConnectAsync(testHelper, serverType, query, queryTempFile.FilePath);
|
||||
Thread.Sleep(10000);
|
||||
await VerifyBindingLoadScenario(testHelper, serverType, query);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task BindingCacheColdAzureComplexQuery()
|
||||
{
|
||||
using (TestHelper testHelper = new TestHelper())
|
||||
{
|
||||
await VerifyBindingLoadScenario(testHelper, TestServerType.Azure, Scripts.ComplexQuery);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task BindingCacheColdOnPremComplexQuery()
|
||||
{
|
||||
using (TestHelper testHelper = new TestHelper())
|
||||
{
|
||||
await VerifyBindingLoadScenario(testHelper, TestServerType.OnPrem, Scripts.ComplexQuery);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task BindingCacheWarmAzureComplexQuery()
|
||||
{
|
||||
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
|
||||
using (TestHelper testHelper = new TestHelper())
|
||||
{
|
||||
string query = Scripts.ComplexQuery;
|
||||
const TestServerType serverType = TestServerType.Azure;
|
||||
await Common.ConnectAsync(testHelper, serverType, query, queryTempFile.FilePath);
|
||||
Thread.Sleep(10000);
|
||||
await VerifyBindingLoadScenario(testHelper, serverType, query);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task BindingCacheWarmOnPremComplexQuery()
|
||||
{
|
||||
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
|
||||
using (TestHelper testHelper = new TestHelper())
|
||||
{
|
||||
string query = Scripts.ComplexQuery;
|
||||
const TestServerType serverType = TestServerType.OnPrem;
|
||||
await Common.ConnectAsync(testHelper, serverType, query, queryTempFile.FilePath);
|
||||
Thread.Sleep(10000);
|
||||
await VerifyBindingLoadScenario(testHelper, serverType, query);
|
||||
}
|
||||
}
|
||||
|
||||
#region Private Helper Methods
|
||||
|
||||
private static async Task VerifyBindingLoadScenario(TestHelper testHelper, TestServerType serverType, string query, [CallerMemberName] string testName = "")
|
||||
{
|
||||
using(SelfCleaningTempFile testTempFile = new SelfCleaningTempFile()) {
|
||||
testHelper.WriteToFile(testTempFile.FilePath, query);
|
||||
await Common.ConnectAsync(testHelper, serverType, query, testTempFile.FilePath);
|
||||
await ValidateCompletionResponse(testHelper, testTempFile.FilePath, query, testName);
|
||||
await testHelper.Disconnect(testTempFile.FilePath);
|
||||
}
|
||||
}
|
||||
|
||||
private static async Task ValidateCompletionResponse(TestHelper testHelper, string ownerUri, string query, [CallerMemberName] string testName="")
|
||||
{
|
||||
TestTimer timer = new TestTimer();
|
||||
await Common.ExecuteWithTimeout(timer, 60000, async () =>
|
||||
{
|
||||
CompletionItem[] completions = await testHelper.RequestCompletion(ownerUri, query, 0, 15);
|
||||
return completions != null && completions.Any(x => x.Label == "master");
|
||||
}, testName:testName);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.TestDriver.Scripts;
|
||||
using Microsoft.SqlTools.ServiceLayer.TestDriver.Tests;
|
||||
using Microsoft.SqlTools.ServiceLayer.TestDriver.Utility;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.PerfTests.Tests
|
||||
{
|
||||
public class QueryExecutionTests
|
||||
{
|
||||
[Fact]
|
||||
public async Task QueryResultSummaryOnPremTest()
|
||||
{
|
||||
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
|
||||
using (TestHelper testHelper = new TestHelper())
|
||||
{
|
||||
const string query = Scripts.SimpleQuery;
|
||||
|
||||
await Common.ConnectAsync(testHelper, TestServerType.OnPrem, query, queryTempFile.FilePath);
|
||||
var queryResult = await Common.CalculateRunTime(() => testHelper.RunQuery(queryTempFile.FilePath, query));
|
||||
|
||||
Assert.NotNull(queryResult);
|
||||
Assert.True(queryResult.BatchSummaries.Any(x => x.ResultSetSummaries.Any(r => r.RowCount > 0)));
|
||||
|
||||
await testHelper.Disconnect(queryTempFile.FilePath);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task QueryResultFirstOnPremTest()
|
||||
{
|
||||
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
|
||||
using (TestHelper testHelper = new TestHelper())
|
||||
{
|
||||
const string query = Scripts.SimpleQuery;
|
||||
|
||||
await Common.ConnectAsync(testHelper, TestServerType.OnPrem, query, queryTempFile.FilePath);
|
||||
|
||||
var queryResult = await Common.CalculateRunTime(async () =>
|
||||
{
|
||||
await testHelper.RunQuery(queryTempFile.FilePath, query);
|
||||
return await testHelper.ExecuteSubset(queryTempFile.FilePath, 0, 0, 0, 100);
|
||||
});
|
||||
|
||||
Assert.NotNull(queryResult);
|
||||
Assert.NotNull(queryResult.ResultSubset);
|
||||
Assert.True(queryResult.ResultSubset.Rows.Any());
|
||||
|
||||
await testHelper.Disconnect(queryTempFile.FilePath);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task CancelQueryOnPremTest()
|
||||
{
|
||||
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
|
||||
using (TestHelper testHelper = new TestHelper())
|
||||
{
|
||||
await Common.ConnectAsync(testHelper, TestServerType.OnPrem, Scripts.DelayQuery, queryTempFile.FilePath);
|
||||
var queryParams = new QueryExecuteParams
|
||||
{
|
||||
OwnerUri = queryTempFile.FilePath,
|
||||
QuerySelection = null
|
||||
};
|
||||
|
||||
var result = await testHelper.Driver.SendRequest(QueryExecuteRequest.Type, queryParams);
|
||||
if (result != null && string.IsNullOrEmpty(result.Messages))
|
||||
{
|
||||
TestTimer timer = new TestTimer();
|
||||
await Common.ExecuteWithTimeout(timer, 100000,
|
||||
async () => await testHelper.CancelConnect(queryTempFile.FilePath), TimeSpan.FromMilliseconds(10));
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.True(false, "Failed to run the query");
|
||||
}
|
||||
|
||||
await testHelper.Disconnect(queryTempFile.FilePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.SqlTools.ServiceLayer.TestDriver.Scripts;
|
||||
using Microsoft.SqlTools.ServiceLayer.TestDriver.Tests;
|
||||
using Microsoft.SqlTools.ServiceLayer.TestDriver.Utility;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.PerfTests.Tests
|
||||
{
|
||||
public class SaveResultsTests
|
||||
{
|
||||
[Fact]
|
||||
public async Task TestSaveResultsToCsvTest()
|
||||
{
|
||||
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
|
||||
using (SelfCleaningTempFile outputTempFile = new SelfCleaningTempFile())
|
||||
using (TestHelper testHelper = new TestHelper())
|
||||
{
|
||||
const string query = Scripts.SimpleQuery;
|
||||
|
||||
// Execute a query
|
||||
await Common.ConnectAsync(testHelper, TestServerType.OnPrem, query, queryTempFile.FilePath);
|
||||
await testHelper.RunQuery(queryTempFile.FilePath, query);
|
||||
await Common.CalculateRunTime(() => testHelper.SaveAsCsv(queryTempFile.FilePath, outputTempFile.FilePath, 0, 0));
|
||||
await testHelper.Disconnect(queryTempFile.FilePath);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task TestSaveResultsToJsonTest()
|
||||
{
|
||||
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
|
||||
using (SelfCleaningTempFile outputTempFile = new SelfCleaningTempFile())
|
||||
using (TestHelper testHelper = new TestHelper())
|
||||
{
|
||||
const string query = Scripts.SimpleQuery;
|
||||
const TestServerType serverType = TestServerType.OnPrem;
|
||||
|
||||
// Execute a query
|
||||
await Common.ConnectAsync(testHelper, serverType, query, queryTempFile.FilePath);
|
||||
await testHelper.RunQuery(queryTempFile.FilePath, query);
|
||||
await Common.CalculateRunTime(() => testHelper.SaveAsJson(queryTempFile.FilePath, outputTempFile.FilePath, 0, 0));
|
||||
await testHelper.Disconnect(queryTempFile.FilePath);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
29
test/Microsoft.SqlTools.ServiceLayer.PerfTests/project.json
Normal file
29
test/Microsoft.SqlTools.ServiceLayer.PerfTests/project.json
Normal file
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"version": "1.0.0-*",
|
||||
|
||||
"dependencies": {
|
||||
"xunit": "2.1.0",
|
||||
"dotnet-test-xunit": "1.0.0-rc2-192208-24",
|
||||
"Microsoft.SqlTools.ServiceLayer": {
|
||||
"target": "project"
|
||||
},
|
||||
"Microsoft.SqlTools.ServiceLayer.TestDriver": "1.0.0-*"
|
||||
},
|
||||
|
||||
"testRunner": "xunit",
|
||||
|
||||
"frameworks": {
|
||||
"netcoreapp1.0": {
|
||||
"dependencies": {
|
||||
"Microsoft.NETCore.App": {
|
||||
"type": "platform",
|
||||
"version" : "1.0.0"
|
||||
}
|
||||
},
|
||||
"imports": [
|
||||
"dotnet5.4",
|
||||
"portable-net451+win8"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user