mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-19 17:23:55 -05:00
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
215 lines
8.7 KiB
C#
215 lines
8.7 KiB
C#
//
|
|
// 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
|
|
}
|
|
}
|