mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-13 17:23:02 -05:00
Perf Test fixing bugs and Update command (#155)
* Fixed some bugs caused by rafactoring * Verifying a test db is created before running the tests
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.SqlTools.ServiceLayer.TestDriver.Utility;
|
||||
using Xunit.Sdk;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.PerfTests
|
||||
{
|
||||
/// <summary>
|
||||
/// The attribute for each test to create the test db before the test starts
|
||||
/// </summary>
|
||||
public class CreateTestDbAttribute : BeforeAfterTestAttribute
|
||||
{
|
||||
public CreateTestDbAttribute(TestServerType serverType)
|
||||
{
|
||||
ServerType = serverType;
|
||||
}
|
||||
|
||||
public CreateTestDbAttribute(int serverType)
|
||||
{
|
||||
ServerType = (TestServerType)serverType;
|
||||
}
|
||||
|
||||
public TestServerType ServerType { get; set; }
|
||||
public override void Before(MethodInfo methodUnderTest)
|
||||
{
|
||||
Task task = Common.CreateTestDatabase(ServerType);
|
||||
task.Wait();
|
||||
}
|
||||
|
||||
public override void After(MethodInfo methodUnderTest)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,7 @@ namespace Microsoft.SqlTools.ServiceLayer.PerfTests
|
||||
|
||||
Logger.Initialize("testdriver", LogLevel.Verbose);
|
||||
|
||||
return TestRunner.RunTests(args, "Microsoft.SqlTools.ServiceLayer.PerfTests.Tests.").Result;
|
||||
return TestRunner.RunTests(args, "Microsoft.SqlTools.ServiceLayer.PerfTests.").Result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,18 +4,24 @@
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Runtime.CompilerServices;
|
||||
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
|
||||
namespace Microsoft.SqlTools.ServiceLayer.PerfTests
|
||||
{
|
||||
public class Common
|
||||
{
|
||||
public const string PerfTestDatabaseName = "SQLToolsCrossPlatPerfTestDb";
|
||||
public const string MasterDatabaseName = "master";
|
||||
|
||||
|
||||
internal static async Task ExecuteWithTimeout(TestTimer timer, int timeout, Func<Task<bool>> repeatedCode,
|
||||
TimeSpan? delay = null, [CallerMemberName] string testName = "")
|
||||
{
|
||||
@@ -38,7 +44,7 @@ namespace Microsoft.SqlTools.ServiceLayer.PerfTests.Tests
|
||||
}
|
||||
}
|
||||
|
||||
internal static async Task<bool> ConnectAsync(TestHelper testHelper, TestServerType serverType, string query, string ownerUri)
|
||||
internal static async Task<bool> ConnectAsync(TestHelper testHelper, TestServerType serverType, string query, string ownerUri, string databaseName)
|
||||
{
|
||||
testHelper.WriteToFile(ownerUri, query);
|
||||
|
||||
@@ -56,7 +62,8 @@ namespace Microsoft.SqlTools.ServiceLayer.PerfTests.Tests
|
||||
await testHelper.RequestOpenDocumentNotification(openParams);
|
||||
|
||||
Thread.Sleep(500);
|
||||
var connectParams = await testHelper.GetDatabaseConnectionAsync(serverType);
|
||||
var connectParams = await testHelper.GetDatabaseConnectionAsync(serverType, databaseName);
|
||||
|
||||
bool connected = await testHelper.Connect(ownerUri, connectParams);
|
||||
Assert.True(connected, "Connection is successful");
|
||||
Console.WriteLine($"Connection to {connectParams.Connection.ServerName} is successful");
|
||||
@@ -64,13 +71,41 @@ namespace Microsoft.SqlTools.ServiceLayer.PerfTests.Tests
|
||||
return connected;
|
||||
}
|
||||
|
||||
internal static async Task<T> CalculateRunTime<T>(Func<Task<T>> testToRun, [CallerMemberName] string testName = "")
|
||||
internal static async Task<T> CalculateRunTime<T>(Func<Task<T>> testToRun, bool printResult, [CallerMemberName] string testName = "")
|
||||
{
|
||||
TestTimer timer = new TestTimer();
|
||||
TestTimer timer = new TestTimer() { PrintResult = printResult };
|
||||
T result = await testToRun();
|
||||
timer.EndAndPrint(testName);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create the test db if not already exists
|
||||
/// </summary>
|
||||
internal static async Task CreateTestDatabase(TestServerType serverType)
|
||||
{
|
||||
using (TestHelper testHelper = new TestHelper())
|
||||
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
|
||||
{
|
||||
string databaseName = Common.PerfTestDatabaseName;
|
||||
string createDatabaseQuery = Scripts.CreateDatabaseQuery.Replace("#DatabaseName#", databaseName);
|
||||
await RunQuery(testHelper, serverType, Common.MasterDatabaseName, createDatabaseQuery);
|
||||
Console.WriteLine(string.Format(CultureInfo.InvariantCulture, "Verified test database '{0}' is created", databaseName));
|
||||
await RunQuery(testHelper, serverType, databaseName, Scripts.CreateDatabaseObjectsQuery);
|
||||
Console.WriteLine(string.Format(CultureInfo.InvariantCulture, "Verified test database '{0}' SQL types are created", databaseName));
|
||||
}
|
||||
}
|
||||
|
||||
internal static async Task RunQuery(TestHelper testHelper, TestServerType serverType, string databaseName, string query)
|
||||
{
|
||||
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
|
||||
{
|
||||
await Common.ConnectAsync(testHelper, serverType, query, queryTempFile.FilePath, databaseName);
|
||||
var queryResult = await Common.CalculateRunTime(() => testHelper.RunQuery(queryTempFile.FilePath, query, 50000), false);
|
||||
|
||||
await testHelper.Disconnect(queryTempFile.FilePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,18 +11,20 @@ using Microsoft.SqlTools.ServiceLayer.TestDriver.Utility;
|
||||
using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.PerfTests.Tests
|
||||
namespace Microsoft.SqlTools.ServiceLayer.PerfTests
|
||||
{
|
||||
public class ConnectionTests
|
||||
{
|
||||
|
||||
[Fact]
|
||||
[CreateTestDb(TestServerType.Azure)]
|
||||
public async Task ConnectAzureTest()
|
||||
{
|
||||
TestServerType serverType = TestServerType.Azure;
|
||||
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
|
||||
using (TestHelper testHelper = new TestHelper())
|
||||
{
|
||||
const string query = Scripts.SimpleQuery;
|
||||
const string query = Scripts.TestDbSimpleSelectQuery;
|
||||
testHelper.WriteToFile(queryTempFile.FilePath, query);
|
||||
|
||||
DidOpenTextDocumentNotification openParams = new DidOpenTextDocumentNotification
|
||||
@@ -41,20 +43,23 @@ namespace Microsoft.SqlTools.ServiceLayer.PerfTests.Tests
|
||||
Thread.Sleep(500);
|
||||
var connected = await Common.CalculateRunTime(async () =>
|
||||
{
|
||||
var connectParams = await testHelper.GetDatabaseConnectionAsync(TestServerType.Azure);
|
||||
var connectParams = await testHelper.GetDatabaseConnectionAsync(serverType, Common.PerfTestDatabaseName);
|
||||
return await testHelper.Connect(queryTempFile.FilePath, connectParams);
|
||||
});
|
||||
}, true);
|
||||
Assert.True(connected, "Connection was not successful");
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[CreateTestDb(TestServerType.OnPrem)]
|
||||
public async Task ConnectOnPremTest()
|
||||
{
|
||||
TestServerType serverType = TestServerType.OnPrem;
|
||||
|
||||
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
|
||||
using (TestHelper testHelper = new TestHelper())
|
||||
{
|
||||
const string query = Scripts.SimpleQuery;
|
||||
const string query = Scripts.TestDbSimpleSelectQuery;
|
||||
testHelper.WriteToFile(queryTempFile.FilePath, query);
|
||||
|
||||
DidOpenTextDocumentNotification openParams = new DidOpenTextDocumentNotification
|
||||
@@ -73,22 +78,25 @@ namespace Microsoft.SqlTools.ServiceLayer.PerfTests.Tests
|
||||
Thread.Sleep(500);
|
||||
var connected = await Common.CalculateRunTime(async () =>
|
||||
{
|
||||
var connectParams = await testHelper.GetDatabaseConnectionAsync(TestServerType.OnPrem);
|
||||
var connectParams = await testHelper.GetDatabaseConnectionAsync(serverType, Common.PerfTestDatabaseName);
|
||||
return await testHelper.Connect(queryTempFile.FilePath, connectParams);
|
||||
});
|
||||
}, true);
|
||||
Assert.True(connected, "Connection was not successful");
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[CreateTestDb(TestServerType.OnPrem)]
|
||||
public async Task DisconnectTest()
|
||||
{
|
||||
TestServerType serverType = TestServerType.OnPrem;
|
||||
|
||||
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
|
||||
using (TestHelper testHelper = new TestHelper())
|
||||
{
|
||||
await Common.ConnectAsync(testHelper, TestServerType.OnPrem, Scripts.SimpleQuery, queryTempFile.FilePath);
|
||||
await Common.ConnectAsync(testHelper, serverType, Scripts.TestDbSimpleSelectQuery, queryTempFile.FilePath, Common.PerfTestDatabaseName);
|
||||
Thread.Sleep(1000);
|
||||
var connected = await Common.CalculateRunTime(() => testHelper.Disconnect(queryTempFile.FilePath));
|
||||
var connected = await Common.CalculateRunTime(() => testHelper.Disconnect(queryTempFile.FilePath), true);
|
||||
Assert.True(connected);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading;
|
||||
@@ -14,45 +15,53 @@ using Microsoft.SqlTools.ServiceLayer.TestDriver.Utility;
|
||||
using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.PerfTests.Tests
|
||||
namespace Microsoft.SqlTools.ServiceLayer.PerfTests
|
||||
{
|
||||
public class IntellisenseTests
|
||||
{
|
||||
[Fact]
|
||||
[CreateTestDb(TestServerType.OnPrem)]
|
||||
public async Task HoverTestOnPrem()
|
||||
{
|
||||
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
|
||||
TestServerType serverType = TestServerType.OnPrem;
|
||||
using (TestHelper testHelper = new TestHelper())
|
||||
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
|
||||
{
|
||||
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));
|
||||
const string query = Scripts.TestDbSimpleSelectQuery;
|
||||
await Common.ConnectAsync(testHelper, serverType, query, queryTempFile.FilePath, Common.PerfTestDatabaseName);
|
||||
Hover hover = await Common.CalculateRunTime(() => testHelper.RequestHover(queryTempFile.FilePath, query, 0, Scripts.TestDbComplexSelectQueries.Length + 1), true);
|
||||
Assert.NotNull(hover);
|
||||
await testHelper.Disconnect(queryTempFile.FilePath);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[CreateTestDb(TestServerType.OnPrem)]
|
||||
public async Task SuggestionsTest()
|
||||
{
|
||||
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
|
||||
TestServerType serverType = TestServerType.OnPrem;
|
||||
using (TestHelper testHelper = new TestHelper())
|
||||
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
|
||||
{
|
||||
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);
|
||||
const string query = Scripts.TestDbSimpleSelectQuery;
|
||||
await Common.ConnectAsync(testHelper, serverType, query, queryTempFile.FilePath, Common.PerfTestDatabaseName);
|
||||
await ValidateCompletionResponse(testHelper, queryTempFile.FilePath, false, Common.PerfTestDatabaseName, true);
|
||||
await ValidateCompletionResponse(testHelper, queryTempFile.FilePath, true, Common.PerfTestDatabaseName, false);
|
||||
await testHelper.Disconnect(queryTempFile.FilePath);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[CreateTestDb(TestServerType.OnPrem)]
|
||||
public async Task DiagnosticsTests()
|
||||
{
|
||||
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
|
||||
TestServerType serverType = TestServerType.OnPrem;
|
||||
await Common.CreateTestDatabase(serverType);
|
||||
|
||||
using (TestHelper testHelper = new TestHelper())
|
||||
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
|
||||
{
|
||||
await Common.ConnectAsync(testHelper, TestServerType.OnPrem, Scripts.SimpleQuery, queryTempFile.FilePath);
|
||||
await Common.ConnectAsync(testHelper, serverType, Scripts.TestDbSimpleSelectQuery, queryTempFile.FilePath, Common.PerfTestDatabaseName);
|
||||
|
||||
Thread.Sleep(500);
|
||||
var contentChanges = new TextDocumentChangeEvent[1];
|
||||
@@ -84,7 +93,7 @@ namespace Microsoft.SqlTools.ServiceLayer.PerfTests.Tests
|
||||
}
|
||||
};
|
||||
|
||||
TestTimer timer = new TestTimer();
|
||||
TestTimer timer = new TestTimer() { PrintResult = true };
|
||||
await testHelper.RequestChangeTextDocumentNotification(changeParams);
|
||||
await Common.ExecuteWithTimeout(timer, 60000, async () =>
|
||||
{
|
||||
@@ -96,118 +105,172 @@ namespace Microsoft.SqlTools.ServiceLayer.PerfTests.Tests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[CreateTestDb(TestServerType.Azure)]
|
||||
public async Task BindingCacheColdAzureSimpleQuery()
|
||||
{
|
||||
TestServerType serverType = TestServerType.Azure;
|
||||
using (TestHelper testHelper = new TestHelper())
|
||||
{
|
||||
await VerifyBindingLoadScenario(testHelper, TestServerType.Azure, Scripts.SimpleQuery);
|
||||
await VerifyBindingLoadScenario(testHelper, serverType, Scripts.TestDbSimpleSelectQuery, false);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[CreateTestDb(TestServerType.OnPrem)]
|
||||
public async Task BindingCacheColdOnPremSimpleQuery()
|
||||
{
|
||||
TestServerType serverType = TestServerType.OnPrem;
|
||||
using (TestHelper testHelper = new TestHelper())
|
||||
{
|
||||
await VerifyBindingLoadScenario(testHelper, TestServerType.OnPrem, Scripts.SimpleQuery);
|
||||
await VerifyBindingLoadScenario(testHelper, TestServerType.OnPrem, Scripts.TestDbSimpleSelectQuery, false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[CreateTestDb(TestServerType.Azure)]
|
||||
public async Task BindingCacheWarmAzureSimpleQuery()
|
||||
{
|
||||
TestServerType serverType = TestServerType.Azure;
|
||||
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);
|
||||
const string query = Scripts.TestDbSimpleSelectQuery;
|
||||
await VerifyBindingLoadScenario(testHelper, serverType, query, true);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[CreateTestDb(TestServerType.OnPrem)]
|
||||
public async Task BindingCacheWarmOnPremSimpleQuery()
|
||||
{
|
||||
TestServerType serverType = TestServerType.OnPrem;
|
||||
|
||||
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);
|
||||
const string query = Scripts.TestDbSimpleSelectQuery;
|
||||
await VerifyBindingLoadScenario(testHelper, serverType, query, true);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[CreateTestDb(TestServerType.Azure)]
|
||||
public async Task BindingCacheColdAzureComplexQuery()
|
||||
{
|
||||
TestServerType serverType = TestServerType.Azure;
|
||||
|
||||
using (TestHelper testHelper = new TestHelper())
|
||||
{
|
||||
await VerifyBindingLoadScenario(testHelper, TestServerType.Azure, Scripts.ComplexQuery);
|
||||
await VerifyBindingLoadScenario(testHelper, serverType, Scripts.TestDbComplexSelectQueries,false);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[CreateTestDb(TestServerType.Azure)]
|
||||
public async Task BindingCacheColdOnPremComplexQuery()
|
||||
{
|
||||
TestServerType serverType = TestServerType.Azure;
|
||||
using (TestHelper testHelper = new TestHelper())
|
||||
{
|
||||
await VerifyBindingLoadScenario(testHelper, TestServerType.OnPrem, Scripts.ComplexQuery);
|
||||
await VerifyBindingLoadScenario(testHelper, TestServerType.OnPrem, Scripts.TestDbComplexSelectQueries, false);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[CreateTestDb(TestServerType.Azure)]
|
||||
public async Task BindingCacheWarmAzureComplexQuery()
|
||||
{
|
||||
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
|
||||
using (TestHelper testHelper = new TestHelper())
|
||||
{
|
||||
string query = Scripts.ComplexQuery;
|
||||
string query = Scripts.TestDbComplexSelectQueries;
|
||||
const TestServerType serverType = TestServerType.Azure;
|
||||
await Common.ConnectAsync(testHelper, serverType, query, queryTempFile.FilePath);
|
||||
Thread.Sleep(10000);
|
||||
await VerifyBindingLoadScenario(testHelper, serverType, query);
|
||||
await VerifyBindingLoadScenario(testHelper, serverType, query, true);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[CreateTestDb(TestServerType.OnPrem)]
|
||||
public async Task BindingCacheWarmOnPremComplexQuery()
|
||||
{
|
||||
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
|
||||
using (TestHelper testHelper = new TestHelper())
|
||||
{
|
||||
string query = Scripts.ComplexQuery;
|
||||
string query = Scripts.TestDbComplexSelectQueries;
|
||||
const TestServerType serverType = TestServerType.OnPrem;
|
||||
await Common.ConnectAsync(testHelper, serverType, query, queryTempFile.FilePath);
|
||||
Thread.Sleep(10000);
|
||||
await VerifyBindingLoadScenario(testHelper, serverType, query);
|
||||
await VerifyBindingLoadScenario(testHelper, serverType, query, true);
|
||||
}
|
||||
}
|
||||
|
||||
#region Private Helper Methods
|
||||
|
||||
private static async Task VerifyBindingLoadScenario(TestHelper testHelper, TestServerType serverType, string query, [CallerMemberName] string testName = "")
|
||||
private async Task VerifyBindingLoadScenario(
|
||||
TestHelper testHelper,
|
||||
TestServerType serverType,
|
||||
string query,
|
||||
bool preLoad,
|
||||
[CallerMemberName] string testName = "")
|
||||
{
|
||||
using(SelfCleaningTempFile testTempFile = new SelfCleaningTempFile()) {
|
||||
string databaseName = Common.PerfTestDatabaseName;
|
||||
if (preLoad)
|
||||
{
|
||||
await VerifyCompletationLoaded(testHelper, serverType, Scripts.TestDbSimpleSelectQuery,
|
||||
databaseName, printResult: false, testName: testName);
|
||||
Console.WriteLine("Intellisense cache loaded.");
|
||||
}
|
||||
await VerifyCompletationLoaded(testHelper, serverType, query, databaseName,
|
||||
printResult: true, testName: testName);
|
||||
}
|
||||
|
||||
private async Task VerifyCompletationLoaded(
|
||||
TestHelper testHelper,
|
||||
TestServerType serverType,
|
||||
string query,
|
||||
string databaseName,
|
||||
bool printResult,
|
||||
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 Common.ConnectAsync(testHelper, serverType, query, testTempFile.FilePath, databaseName);
|
||||
await ValidateCompletionResponse(testHelper, testTempFile.FilePath, printResult, databaseName,
|
||||
waitForIntelliSense: true, testName: testName);
|
||||
await testHelper.Disconnect(testTempFile.FilePath);
|
||||
}
|
||||
}
|
||||
|
||||
private static async Task ValidateCompletionResponse(TestHelper testHelper, string ownerUri, string query, [CallerMemberName] string testName="")
|
||||
private static async Task ValidateCompletionResponse(
|
||||
TestHelper testHelper,
|
||||
string ownerUri,
|
||||
bool printResult,
|
||||
string databaseName,
|
||||
bool waitForIntelliSense,
|
||||
[CallerMemberName] string testName = "")
|
||||
{
|
||||
TestTimer timer = new TestTimer();
|
||||
await Common.ExecuteWithTimeout(timer, 60000, async () =>
|
||||
TestTimer timer = new TestTimer() { PrintResult = printResult };
|
||||
bool isReady = !waitForIntelliSense;
|
||||
await Common.ExecuteWithTimeout(timer, 150000, async () =>
|
||||
{
|
||||
CompletionItem[] completions = await testHelper.RequestCompletion(ownerUri, query, 0, 15);
|
||||
return completions != null && completions.Any(x => x.Label == "master");
|
||||
}, testName:testName);
|
||||
}
|
||||
if (isReady)
|
||||
{
|
||||
string query = Scripts.SelectQuery;
|
||||
CompletionItem[] completions = await testHelper.RequestCompletion(ownerUri, query, 0, query.Length + 1);
|
||||
return completions != null && completions.Any(x => x.Label == databaseName);
|
||||
}
|
||||
else
|
||||
{
|
||||
var completeEvent = await testHelper.Driver.WaitForEvent(IntelliSenseReadyNotification.Type, 100000);
|
||||
isReady = completeEvent.OwnerUri == ownerUri;
|
||||
if (isReady)
|
||||
{
|
||||
Console.WriteLine("IntelliSense cache is loaded.");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}, testName: testName);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
@@ -12,20 +12,22 @@ using Microsoft.SqlTools.ServiceLayer.TestDriver.Tests;
|
||||
using Microsoft.SqlTools.ServiceLayer.TestDriver.Utility;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.PerfTests.Tests
|
||||
namespace Microsoft.SqlTools.ServiceLayer.PerfTests
|
||||
{
|
||||
public class QueryExecutionTests
|
||||
{
|
||||
[Fact]
|
||||
public async Task QueryResultSummaryOnPremTest()
|
||||
{
|
||||
TestServerType serverType = TestServerType.OnPrem;
|
||||
|
||||
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
|
||||
using (TestHelper testHelper = new TestHelper())
|
||||
{
|
||||
const string query = Scripts.SimpleQuery;
|
||||
const string query = Scripts.MasterBasicQuery;
|
||||
|
||||
await Common.ConnectAsync(testHelper, TestServerType.OnPrem, query, queryTempFile.FilePath);
|
||||
var queryResult = await Common.CalculateRunTime(() => testHelper.RunQuery(queryTempFile.FilePath, query));
|
||||
await Common.ConnectAsync(testHelper, serverType, query, queryTempFile.FilePath, Common.MasterDatabaseName);
|
||||
var queryResult = await Common.CalculateRunTime(() => testHelper.RunQuery(queryTempFile.FilePath, query), true);
|
||||
|
||||
Assert.NotNull(queryResult);
|
||||
Assert.True(queryResult.BatchSummaries.Any(x => x.ResultSetSummaries.Any(r => r.RowCount > 0)));
|
||||
@@ -37,18 +39,20 @@ namespace Microsoft.SqlTools.ServiceLayer.PerfTests.Tests
|
||||
[Fact]
|
||||
public async Task QueryResultFirstOnPremTest()
|
||||
{
|
||||
TestServerType serverType = TestServerType.OnPrem;
|
||||
|
||||
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
|
||||
using (TestHelper testHelper = new TestHelper())
|
||||
{
|
||||
const string query = Scripts.SimpleQuery;
|
||||
const string query = Scripts.MasterBasicQuery;
|
||||
|
||||
await Common.ConnectAsync(testHelper, TestServerType.OnPrem, query, queryTempFile.FilePath);
|
||||
await Common.ConnectAsync(testHelper, serverType, query, queryTempFile.FilePath, Common.MasterDatabaseName);
|
||||
|
||||
var queryResult = await Common.CalculateRunTime(async () =>
|
||||
{
|
||||
await testHelper.RunQuery(queryTempFile.FilePath, query);
|
||||
return await testHelper.ExecuteSubset(queryTempFile.FilePath, 0, 0, 0, 100);
|
||||
});
|
||||
}, true);
|
||||
|
||||
Assert.NotNull(queryResult);
|
||||
Assert.NotNull(queryResult.ResultSubset);
|
||||
@@ -59,12 +63,15 @@ namespace Microsoft.SqlTools.ServiceLayer.PerfTests.Tests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[CreateTestDb(TestServerType.OnPrem)]
|
||||
public async Task CancelQueryOnPremTest()
|
||||
{
|
||||
TestServerType serverType = TestServerType.OnPrem;
|
||||
|
||||
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
|
||||
using (TestHelper testHelper = new TestHelper())
|
||||
{
|
||||
await Common.ConnectAsync(testHelper, TestServerType.OnPrem, Scripts.DelayQuery, queryTempFile.FilePath);
|
||||
await Common.ConnectAsync(testHelper, serverType, Scripts.DelayQuery, queryTempFile.FilePath, Common.PerfTestDatabaseName);
|
||||
var queryParams = new QueryExecuteParams
|
||||
{
|
||||
OwnerUri = queryTempFile.FilePath,
|
||||
@@ -74,9 +81,12 @@ namespace Microsoft.SqlTools.ServiceLayer.PerfTests.Tests
|
||||
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));
|
||||
TestTimer timer = new TestTimer() { PrintResult = true };
|
||||
await Common.ExecuteWithTimeout(timer, 100000, async () =>
|
||||
{
|
||||
var cancelQueryResult = await testHelper.CancelQuery(queryTempFile.FilePath);
|
||||
return true;
|
||||
}, TimeSpan.FromMilliseconds(10));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -9,23 +9,25 @@ using Microsoft.SqlTools.ServiceLayer.TestDriver.Tests;
|
||||
using Microsoft.SqlTools.ServiceLayer.TestDriver.Utility;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.PerfTests.Tests
|
||||
namespace Microsoft.SqlTools.ServiceLayer.PerfTests
|
||||
{
|
||||
public class SaveResultsTests
|
||||
{
|
||||
[Fact]
|
||||
public async Task TestSaveResultsToCsvTest()
|
||||
{
|
||||
TestServerType serverType = TestServerType.OnPrem;
|
||||
|
||||
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
|
||||
using (SelfCleaningTempFile outputTempFile = new SelfCleaningTempFile())
|
||||
using (TestHelper testHelper = new TestHelper())
|
||||
{
|
||||
const string query = Scripts.SimpleQuery;
|
||||
const string query = Scripts.MasterBasicQuery;
|
||||
|
||||
// Execute a query
|
||||
await Common.ConnectAsync(testHelper, TestServerType.OnPrem, query, queryTempFile.FilePath);
|
||||
await Common.ConnectAsync(testHelper, serverType, query, queryTempFile.FilePath, Common.MasterDatabaseName);
|
||||
await testHelper.RunQuery(queryTempFile.FilePath, query);
|
||||
await Common.CalculateRunTime(() => testHelper.SaveAsCsv(queryTempFile.FilePath, outputTempFile.FilePath, 0, 0));
|
||||
await Common.CalculateRunTime(() => testHelper.SaveAsCsv(queryTempFile.FilePath, outputTempFile.FilePath, 0, 0), true);
|
||||
await testHelper.Disconnect(queryTempFile.FilePath);
|
||||
}
|
||||
}
|
||||
@@ -33,17 +35,18 @@ namespace Microsoft.SqlTools.ServiceLayer.PerfTests.Tests
|
||||
[Fact]
|
||||
public async Task TestSaveResultsToJsonTest()
|
||||
{
|
||||
TestServerType serverType = TestServerType.OnPrem;
|
||||
|
||||
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;
|
||||
const string query = Scripts.MasterBasicQuery;
|
||||
|
||||
// Execute a query
|
||||
await Common.ConnectAsync(testHelper, serverType, query, queryTempFile.FilePath);
|
||||
await Common.ConnectAsync(testHelper, serverType, query, queryTempFile.FilePath, Common.MasterDatabaseName);
|
||||
await testHelper.RunQuery(queryTempFile.FilePath, query);
|
||||
await Common.CalculateRunTime(() => testHelper.SaveAsJson(queryTempFile.FilePath, outputTempFile.FilePath, 0, 0));
|
||||
await Common.CalculateRunTime(() => testHelper.SaveAsJson(queryTempFile.FilePath, outputTempFile.FilePath, 0, 0), true);
|
||||
await testHelper.Disconnect(queryTempFile.FilePath);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,18 @@
|
||||
{
|
||||
"name": "Microsoft.SqlTools.ServiceLayer.PerfTests",
|
||||
"version": "1.0.0-*",
|
||||
|
||||
"buildOptions": {
|
||||
"debugType": "portable",
|
||||
"emitEntryPoint": true
|
||||
},
|
||||
"dependencies": {
|
||||
"xunit": "2.1.0",
|
||||
"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-*"
|
||||
},
|
||||
"Microsoft.SqlTools.ServiceLayer.TestDriver": "1.0.0-*"
|
||||
},
|
||||
|
||||
"testRunner": "xunit",
|
||||
|
||||
@@ -16,14 +20,16 @@
|
||||
"netcoreapp1.0": {
|
||||
"dependencies": {
|
||||
"Microsoft.NETCore.App": {
|
||||
"type": "platform",
|
||||
"version" : "1.0.0"
|
||||
}
|
||||
"version": "1.0.0"
|
||||
}
|
||||
},
|
||||
"imports": [
|
||||
"dotnet5.4",
|
||||
"portable-net451+win8"
|
||||
]
|
||||
}
|
||||
},
|
||||
"runtimes": {
|
||||
"win7-x64": {}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user