mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-03 17:24:53 -05:00
Multiple batch execution time (#664)
* fixed bug where execution time was wrong for multiple batches * fixed bug where multiple execution would show wrong execution time * simplified logic
This commit is contained in:
@@ -1,4 +1,9 @@
|
||||
|
||||
//
|
||||
// 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.Collections.Concurrent;
|
||||
using System.Data.Common;
|
||||
using Microsoft.SqlTools.ServiceLayer.Connection;
|
||||
@@ -98,6 +103,18 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.QueryExecution
|
||||
Assert.Equal(master, connInfo.ConnectionDetails.DatabaseName);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestBatchExecutionTime() {
|
||||
var result = LiveConnectionHelper.InitLiveConnectionInfo();
|
||||
ConnectionInfo connInfo = result.ConnectionInfo;
|
||||
var fileStreamFactory = MemoryFileSystem.GetFileStreamFactory();
|
||||
Query query = CreateAndExecuteQuery("select * from sys.databases", connInfo, fileStreamFactory);
|
||||
DateTime elapsedTime = Convert.ToDateTime(query.Batches[0].ExecutionElapsedTime);
|
||||
Query mutipleQuery = CreateAndExecuteQuery("select * from sys.databases\r\nGO 15", connInfo, fileStreamFactory);
|
||||
DateTime multipleElapsedTime = Convert.ToDateTime(mutipleQuery.Batches[0].ExecutionElapsedTime);
|
||||
Assert.True(multipleElapsedTime > elapsedTime);
|
||||
}
|
||||
|
||||
public Query CreateAndExecuteQuery(string queryText, ConnectionInfo connectionInfo, IFileStreamFactory fileStreamFactory)
|
||||
{
|
||||
Query query = new Query(queryText, connectionInfo, new QueryExecutionSettings(), fileStreamFactory);
|
||||
@@ -105,5 +122,6 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.QueryExecution
|
||||
query.ExecutionTask.Wait();
|
||||
return query;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Data.SqlClient;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.SqlServer.Management.Common;
|
||||
using Microsoft.SqlTools.ServiceLayer.Connection;
|
||||
using Microsoft.SqlTools.ServiceLayer.Connection.Contracts;
|
||||
@@ -19,13 +19,13 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Utility
|
||||
public static string GetTestSqlFile(string fileName = null)
|
||||
{
|
||||
string filePath = null;
|
||||
if (string.IsNullOrEmpty(fileName))
|
||||
{
|
||||
filePath = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "sqltest.sql");
|
||||
}
|
||||
else
|
||||
{
|
||||
filePath = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), fileName + ".sql");
|
||||
if (string.IsNullOrEmpty(fileName))
|
||||
{
|
||||
filePath = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "sqltest.sql");
|
||||
}
|
||||
else
|
||||
{
|
||||
filePath = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), fileName + ".sql");
|
||||
}
|
||||
|
||||
if (File.Exists(filePath))
|
||||
@@ -39,12 +39,12 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Utility
|
||||
public static TestConnectionResult InitLiveConnectionInfo(string databaseName = null, string ownerUri = null)
|
||||
{
|
||||
ScriptFile scriptFile = null;
|
||||
ConnectParams connectParams = TestServiceProvider.Instance.ConnectionProfileService.GetConnectionParameters(TestServerType.OnPrem, databaseName);
|
||||
if (string.IsNullOrEmpty(ownerUri))
|
||||
{
|
||||
ownerUri = GetTestSqlFile();
|
||||
scriptFile = TestServiceProvider.Instance.WorkspaceService.Workspace.GetFile(ownerUri);
|
||||
ownerUri = scriptFile.ClientFilePath;
|
||||
ConnectParams connectParams = TestServiceProvider.Instance.ConnectionProfileService.GetConnectionParameters(TestServerType.OnPrem, databaseName);
|
||||
if (string.IsNullOrEmpty(ownerUri))
|
||||
{
|
||||
ownerUri = GetTestSqlFile();
|
||||
scriptFile = TestServiceProvider.Instance.WorkspaceService.Workspace.GetFile(ownerUri);
|
||||
ownerUri = scriptFile.ClientFilePath;
|
||||
}
|
||||
var connectionService = GetLiveTestConnectionService();
|
||||
var connectionResult =
|
||||
@@ -64,15 +64,15 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Utility
|
||||
|
||||
public static async Task<TestConnectionResult> InitLiveConnectionInfoAsync(string databaseName = null, string ownerUri = null,
|
||||
string connectionType = ServiceLayer.Connection.ConnectionType.Default)
|
||||
{
|
||||
{
|
||||
ScriptFile scriptFile = null;
|
||||
if (string.IsNullOrEmpty(ownerUri))
|
||||
{
|
||||
ownerUri = GetTestSqlFile();
|
||||
scriptFile = TestServiceProvider.Instance.WorkspaceService.Workspace.GetFile(ownerUri);
|
||||
ownerUri = scriptFile.ClientFilePath;
|
||||
}
|
||||
ConnectParams connectParams = TestServiceProvider.Instance.ConnectionProfileService.GetConnectionParameters(TestServerType.OnPrem, databaseName);
|
||||
if (string.IsNullOrEmpty(ownerUri))
|
||||
{
|
||||
ownerUri = GetTestSqlFile();
|
||||
scriptFile = TestServiceProvider.Instance.WorkspaceService.Workspace.GetFile(ownerUri);
|
||||
ownerUri = scriptFile.ClientFilePath;
|
||||
}
|
||||
ConnectParams connectParams = TestServiceProvider.Instance.ConnectionProfileService.GetConnectionParameters(TestServerType.OnPrem, databaseName);
|
||||
|
||||
var connectionService = GetLiveTestConnectionService();
|
||||
var connectionResult =
|
||||
@@ -83,9 +83,9 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Utility
|
||||
Connection = connectParams.Connection,
|
||||
Type = connectionType
|
||||
});
|
||||
if (!string.IsNullOrEmpty(connectionResult.ErrorMessage))
|
||||
{
|
||||
Console.WriteLine(connectionResult.ErrorMessage);
|
||||
if (!string.IsNullOrEmpty(connectionResult.ErrorMessage))
|
||||
{
|
||||
Console.WriteLine(connectionResult.ErrorMessage);
|
||||
}
|
||||
|
||||
ConnectionInfo connInfo = null;
|
||||
@@ -95,26 +95,26 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Utility
|
||||
|
||||
public static ConnectionInfo InitLiveConnectionInfoForDefinition(string databaseName = null)
|
||||
{
|
||||
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
|
||||
{
|
||||
ConnectParams connectParams = TestServiceProvider.Instance.ConnectionProfileService.GetConnectionParameters(TestServerType.OnPrem, databaseName);
|
||||
string ownerUri = queryTempFile.FilePath;
|
||||
var connectionService = GetLiveTestConnectionService();
|
||||
var connectionResult =
|
||||
connectionService
|
||||
.Connect(new ConnectParams
|
||||
{
|
||||
OwnerUri = ownerUri,
|
||||
Connection = connectParams.Connection
|
||||
});
|
||||
|
||||
connectionResult.Wait();
|
||||
|
||||
ConnectionInfo connInfo = null;
|
||||
connectionService.TryFindConnection(ownerUri, out connInfo);
|
||||
|
||||
Assert.NotNull(connInfo);
|
||||
return connInfo;
|
||||
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
|
||||
{
|
||||
ConnectParams connectParams = TestServiceProvider.Instance.ConnectionProfileService.GetConnectionParameters(TestServerType.OnPrem, databaseName);
|
||||
string ownerUri = queryTempFile.FilePath;
|
||||
var connectionService = GetLiveTestConnectionService();
|
||||
var connectionResult =
|
||||
connectionService
|
||||
.Connect(new ConnectParams
|
||||
{
|
||||
OwnerUri = ownerUri,
|
||||
Connection = connectParams.Connection
|
||||
});
|
||||
|
||||
connectionResult.Wait();
|
||||
|
||||
ConnectionInfo connInfo = null;
|
||||
connectionService.TryFindConnection(ownerUri, out connInfo);
|
||||
|
||||
Assert.NotNull(connInfo);
|
||||
return connInfo;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user