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:
Aditya Bist
2018-07-25 16:45:26 -07:00
committed by GitHub
parent 7c96ceb501
commit f293a54af7
3 changed files with 68 additions and 49 deletions

View File

@@ -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)

View File

@@ -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;
} }
} }
} }