mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-16 10:58:30 -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:
@@ -303,6 +303,8 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
|||||||
|
|
||||||
await SendMessageIfExecutingMultipleTimes(SR.EE_ExecutionInfo_InitializingLoop, false);
|
await SendMessageIfExecutingMultipleTimes(SR.EE_ExecutionInfo_InitializingLoop, false);
|
||||||
|
|
||||||
|
executionStartTime = DateTime.Now;
|
||||||
|
|
||||||
while (canContinue && timesLoop > 0)
|
while (canContinue && timesLoop > 0)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@@ -353,7 +355,6 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
|||||||
dbCommand.CommandText = BatchText;
|
dbCommand.CommandText = BatchText;
|
||||||
dbCommand.CommandType = CommandType.Text;
|
dbCommand.CommandType = CommandType.Text;
|
||||||
dbCommand.CommandTimeout = 0;
|
dbCommand.CommandTimeout = 0;
|
||||||
executionStartTime = DateTime.Now;
|
|
||||||
|
|
||||||
List<DbColumn[]> columnSchemas = null;
|
List<DbColumn[]> columnSchemas = null;
|
||||||
if (getFullColumnSchema)
|
if (getFullColumnSchema)
|
||||||
|
|||||||
@@ -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.Collections.Concurrent;
|
||||||
using System.Data.Common;
|
using System.Data.Common;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Connection;
|
using Microsoft.SqlTools.ServiceLayer.Connection;
|
||||||
@@ -98,6 +103,18 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.QueryExecution
|
|||||||
Assert.Equal(master, connInfo.ConnectionDetails.DatabaseName);
|
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)
|
public Query CreateAndExecuteQuery(string queryText, ConnectionInfo connectionInfo, IFileStreamFactory fileStreamFactory)
|
||||||
{
|
{
|
||||||
Query query = new Query(queryText, connectionInfo, new QueryExecutionSettings(), fileStreamFactory);
|
Query query = new Query(queryText, connectionInfo, new QueryExecutionSettings(), fileStreamFactory);
|
||||||
@@ -105,5 +122,6 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.QueryExecution
|
|||||||
query.ExecutionTask.Wait();
|
query.ExecutionTask.Wait();
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Data.SqlClient;
|
using System.Data.SqlClient;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.SqlServer.Management.Common;
|
using Microsoft.SqlServer.Management.Common;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Connection;
|
using Microsoft.SqlTools.ServiceLayer.Connection;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Connection.Contracts;
|
using Microsoft.SqlTools.ServiceLayer.Connection.Contracts;
|
||||||
@@ -19,13 +19,13 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Utility
|
|||||||
public static string GetTestSqlFile(string fileName = null)
|
public static string GetTestSqlFile(string fileName = null)
|
||||||
{
|
{
|
||||||
string filePath = null;
|
string filePath = null;
|
||||||
if (string.IsNullOrEmpty(fileName))
|
if (string.IsNullOrEmpty(fileName))
|
||||||
{
|
{
|
||||||
filePath = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "sqltest.sql");
|
filePath = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "sqltest.sql");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
filePath = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), fileName + ".sql");
|
filePath = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), fileName + ".sql");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (File.Exists(filePath))
|
if (File.Exists(filePath))
|
||||||
@@ -39,12 +39,12 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Utility
|
|||||||
public static TestConnectionResult InitLiveConnectionInfo(string databaseName = null, string ownerUri = null)
|
public static TestConnectionResult InitLiveConnectionInfo(string databaseName = null, string ownerUri = null)
|
||||||
{
|
{
|
||||||
ScriptFile scriptFile = null;
|
ScriptFile scriptFile = null;
|
||||||
ConnectParams connectParams = TestServiceProvider.Instance.ConnectionProfileService.GetConnectionParameters(TestServerType.OnPrem, databaseName);
|
ConnectParams connectParams = TestServiceProvider.Instance.ConnectionProfileService.GetConnectionParameters(TestServerType.OnPrem, databaseName);
|
||||||
if (string.IsNullOrEmpty(ownerUri))
|
if (string.IsNullOrEmpty(ownerUri))
|
||||||
{
|
{
|
||||||
ownerUri = GetTestSqlFile();
|
ownerUri = GetTestSqlFile();
|
||||||
scriptFile = TestServiceProvider.Instance.WorkspaceService.Workspace.GetFile(ownerUri);
|
scriptFile = TestServiceProvider.Instance.WorkspaceService.Workspace.GetFile(ownerUri);
|
||||||
ownerUri = scriptFile.ClientFilePath;
|
ownerUri = scriptFile.ClientFilePath;
|
||||||
}
|
}
|
||||||
var connectionService = GetLiveTestConnectionService();
|
var connectionService = GetLiveTestConnectionService();
|
||||||
var connectionResult =
|
var connectionResult =
|
||||||
@@ -64,15 +64,15 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Utility
|
|||||||
|
|
||||||
public static async Task<TestConnectionResult> InitLiveConnectionInfoAsync(string databaseName = null, string ownerUri = null,
|
public static async Task<TestConnectionResult> InitLiveConnectionInfoAsync(string databaseName = null, string ownerUri = null,
|
||||||
string connectionType = ServiceLayer.Connection.ConnectionType.Default)
|
string connectionType = ServiceLayer.Connection.ConnectionType.Default)
|
||||||
{
|
{
|
||||||
ScriptFile scriptFile = null;
|
ScriptFile scriptFile = null;
|
||||||
if (string.IsNullOrEmpty(ownerUri))
|
if (string.IsNullOrEmpty(ownerUri))
|
||||||
{
|
{
|
||||||
ownerUri = GetTestSqlFile();
|
ownerUri = GetTestSqlFile();
|
||||||
scriptFile = TestServiceProvider.Instance.WorkspaceService.Workspace.GetFile(ownerUri);
|
scriptFile = TestServiceProvider.Instance.WorkspaceService.Workspace.GetFile(ownerUri);
|
||||||
ownerUri = scriptFile.ClientFilePath;
|
ownerUri = scriptFile.ClientFilePath;
|
||||||
}
|
}
|
||||||
ConnectParams connectParams = TestServiceProvider.Instance.ConnectionProfileService.GetConnectionParameters(TestServerType.OnPrem, databaseName);
|
ConnectParams connectParams = TestServiceProvider.Instance.ConnectionProfileService.GetConnectionParameters(TestServerType.OnPrem, databaseName);
|
||||||
|
|
||||||
var connectionService = GetLiveTestConnectionService();
|
var connectionService = GetLiveTestConnectionService();
|
||||||
var connectionResult =
|
var connectionResult =
|
||||||
@@ -83,9 +83,9 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Utility
|
|||||||
Connection = connectParams.Connection,
|
Connection = connectParams.Connection,
|
||||||
Type = connectionType
|
Type = connectionType
|
||||||
});
|
});
|
||||||
if (!string.IsNullOrEmpty(connectionResult.ErrorMessage))
|
if (!string.IsNullOrEmpty(connectionResult.ErrorMessage))
|
||||||
{
|
{
|
||||||
Console.WriteLine(connectionResult.ErrorMessage);
|
Console.WriteLine(connectionResult.ErrorMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
ConnectionInfo connInfo = null;
|
ConnectionInfo connInfo = null;
|
||||||
@@ -95,26 +95,26 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Utility
|
|||||||
|
|
||||||
public static ConnectionInfo InitLiveConnectionInfoForDefinition(string databaseName = null)
|
public static ConnectionInfo InitLiveConnectionInfoForDefinition(string databaseName = null)
|
||||||
{
|
{
|
||||||
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
|
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
|
||||||
{
|
{
|
||||||
ConnectParams connectParams = TestServiceProvider.Instance.ConnectionProfileService.GetConnectionParameters(TestServerType.OnPrem, databaseName);
|
ConnectParams connectParams = TestServiceProvider.Instance.ConnectionProfileService.GetConnectionParameters(TestServerType.OnPrem, databaseName);
|
||||||
string ownerUri = queryTempFile.FilePath;
|
string ownerUri = queryTempFile.FilePath;
|
||||||
var connectionService = GetLiveTestConnectionService();
|
var connectionService = GetLiveTestConnectionService();
|
||||||
var connectionResult =
|
var connectionResult =
|
||||||
connectionService
|
connectionService
|
||||||
.Connect(new ConnectParams
|
.Connect(new ConnectParams
|
||||||
{
|
{
|
||||||
OwnerUri = ownerUri,
|
OwnerUri = ownerUri,
|
||||||
Connection = connectParams.Connection
|
Connection = connectParams.Connection
|
||||||
});
|
});
|
||||||
|
|
||||||
connectionResult.Wait();
|
connectionResult.Wait();
|
||||||
|
|
||||||
ConnectionInfo connInfo = null;
|
ConnectionInfo connInfo = null;
|
||||||
connectionService.TryFindConnection(ownerUri, out connInfo);
|
connectionService.TryFindConnection(ownerUri, out connInfo);
|
||||||
|
|
||||||
Assert.NotNull(connInfo);
|
Assert.NotNull(connInfo);
|
||||||
return connInfo;
|
return connInfo;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user