Files
sqltoolsservice/test/Microsoft.SqlTools.ServiceLayer.TestDriver/Tests/LanguageServiceTests.cs
Benjamin Russell db1e4ae351 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
2016-11-18 17:46:56 -08:00

260 lines
9.2 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.Threading;
using System.Threading.Tasks;
using Microsoft.SqlTools.ServiceLayer.LanguageServices.Contracts;
using Microsoft.SqlTools.ServiceLayer.SqlContext;
using Microsoft.SqlTools.ServiceLayer.TestDriver.Utility;
using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts;
using Xunit;
namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Tests
{
/// <summary>
/// Language Service end-to-end integration tests
/// </summary>
public class LanguageServiceTests
{
/// <summary>
/// Validate hover tooltip scenarios
/// </summary>
[Fact]
public async Task HoverTest()
{
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
using (TestHelper testHelper = new TestHelper())
{
string query = "SELECT * FROM sys.objects";
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);
bool connected = await testHelper.Connect(queryTempFile.FilePath, ConnectionTestUtils.LocalhostConnection);
Assert.True(connected, "Connection was not successful");
Thread.Sleep(10000);
Hover hover = await testHelper.RequestHover(queryTempFile.FilePath, query, 0, 15);
Assert.True(hover != null, "Hover tooltop is null");
await testHelper.Disconnect(queryTempFile.FilePath);
}
}
/// <summary>
/// Validation autocompletion suggestions scenarios
/// </summary>
[Fact]
public async Task CompletionTest()
{
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
using (TestHelper testHelper = new TestHelper())
{
string query = "SELECT * FROM sys.objects";
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);
bool connected = await testHelper.Connect(queryTempFile.FilePath, ConnectionTestUtils.LocalhostConnection);
Assert.True(connected, "Connection is successful");
Thread.Sleep(10000);
CompletionItem[] completions = await testHelper.RequestCompletion(queryTempFile.FilePath, query, 0, 15);
Assert.True(completions != null && completions.Length > 0, "Completion items list is null or empty");
Thread.Sleep(50);
await testHelper.RequestResolveCompletion(completions[0]);
Assert.True(completions != null && completions.Length > 0, "Completion items list is null or empty");
await testHelper.Disconnect(queryTempFile.FilePath);
}
}
/// <summary>
/// Validate diagnostic scenarios
/// </summary>
[Fact]
public async Task DiagnosticsTests()
{
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
using (TestHelper testHelper = new TestHelper())
{
bool connected = await testHelper.Connect(queryTempFile.FilePath, ConnectionTestUtils.LocalhostConnection);
Assert.True(connected, "Connection was not successful");
Thread.Sleep(500);
string query = "SELECT *** FROM sys.objects";
DidOpenTextDocumentNotification openParams = new DidOpenTextDocumentNotification
{
TextDocument = new TextDocumentItem
{
Uri = queryTempFile.FilePath,
LanguageId = "enu",
Version = 1,
Text = query
}
};
await testHelper.RequestOpenDocumentNotification(openParams);
Thread.Sleep(100);
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
}
};
await testHelper.RequestChangeTextDocumentNotification(changeParams);
Thread.Sleep(100);
contentChanges[0] = new TextDocumentChangeEvent
{
Range = new Range
{
Start = new Position
{
Line = 0,
Character = 5
},
End = new Position
{
Line = 0,
Character = 6
}
},
RangeLength = 1,
Text = "t"
};
changeParams = new DidChangeTextDocumentParams
{
ContentChanges = contentChanges,
TextDocument = new VersionedTextDocumentIdentifier
{
Version = 3,
Uri = queryTempFile.FilePath
}
};
await testHelper.RequestChangeTextDocumentNotification(changeParams);
Thread.Sleep(2500);
await testHelper.Disconnect(queryTempFile.FilePath);
}
}
/// <summary>
/// Validate the configuration change event
/// </summary>
[Fact]
public async Task ChangeConfigurationTest()
{
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
using (TestHelper testHelper = new TestHelper())
{
bool connected = await testHelper.Connect(queryTempFile.FilePath, ConnectionTestUtils.LocalhostConnection);
Assert.True(connected, "Connection was not successful");
Thread.Sleep(500);
var settings = new SqlToolsSettings();
settings.SqlTools.IntelliSense.EnableIntellisense = false;
DidChangeConfigurationParams<SqlToolsSettings> configParams = new DidChangeConfigurationParams<SqlToolsSettings>()
{
Settings = settings
};
await testHelper.RequestChangeConfigurationNotification(configParams);
Thread.Sleep(2000);
await testHelper.Disconnect(queryTempFile.FilePath);
}
}
[Fact]
public async Task NotificationIsSentAfterOnConnectionAutoCompleteUpdate()
{
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
using (TestHelper testHelper = new TestHelper())
{
// Connect
await testHelper.Connect(queryTempFile.FilePath, ConnectionTestUtils.LocalhostConnection);
// An event signalling that IntelliSense is ready should be sent shortly thereafter
var readyParams = await testHelper.Driver.WaitForEvent(IntelliSenseReadyNotification.Type, 30000);
Assert.NotNull(readyParams);
Assert.Equal(queryTempFile.FilePath, readyParams.OwnerUri);
await testHelper.Disconnect(queryTempFile.FilePath);
}
}
}
}