mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-16 10:58:30 -05:00
Fix for : 4045: Cannot cancel a Query. Query runs too long. (And SMO update) (#780)
* Fix for : 4045: Cannot cancel a Query. Query runs too long. HandleExecuteRequest was returning a task to awaiter - which was getting waited on. changed it to async function to start task in new thread and return nothing to awaiter . Also the cancellation token set by cancel request was getting checked only after making the connection to execute batches. Added an additional check for cancellation token befor the connection has been made. Fix for 4319: Error showing dbs when using AAD in... 1.5.0-alpha.74 David has already created a new version of SMO nuget with the fix. - incorporating the same (150.18096.0-preview). * Adding awaitable internal task for tests to run properly * Adding more cancel tests
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
<Project>
|
<Project>
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
|
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
|
||||||
<SmoPackageVersion>150.18085.0-preview</SmoPackageVersion>
|
<SmoPackageVersion>150.18096.0-preview</SmoPackageVersion>
|
||||||
<HighEntropyVA>true</HighEntropyVA>
|
<HighEntropyVA>true</HighEntropyVA>
|
||||||
<TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
|
<TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|||||||
@@ -226,7 +226,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (!HasExecuted)
|
if (!HasExecuted && !HasCancelled)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException("Query has not been executed.");
|
throw new InvalidOperationException("Query has not been executed.");
|
||||||
}
|
}
|
||||||
@@ -259,6 +259,11 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// if the query has been cancelled (before execution started)
|
||||||
|
/// </summary>
|
||||||
|
public bool HasCancelled { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The text of the query to execute
|
/// The text of the query to execute
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -280,6 +285,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Issue the cancellation token for the query
|
// Issue the cancellation token for the query
|
||||||
|
this.HasCancelled = true;
|
||||||
cancellationSource.Cancel();
|
cancellationSource.Cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -368,9 +374,12 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
|||||||
ReliableSqlConnection sqlConn = null;
|
ReliableSqlConnection sqlConn = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
// check for cancellation token before actually making connection
|
||||||
|
cancellationSource.Token.ThrowIfCancellationRequested();
|
||||||
|
|
||||||
// Mark that we've internally executed
|
// Mark that we've internally executed
|
||||||
hasExecuteBeenCalled = true;
|
hasExecuteBeenCalled = true;
|
||||||
|
|
||||||
// Don't actually execute if there aren't any batches to execute
|
// Don't actually execute if there aren't any batches to execute
|
||||||
if (Batches.Length == 0)
|
if (Batches.Length == 0)
|
||||||
{
|
{
|
||||||
@@ -429,6 +438,10 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
|||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
if (e is OperationCanceledException)
|
||||||
|
{
|
||||||
|
await BatchMessageSent(new ResultMessage(SR.QueryServiceQueryCancelled, false, null));
|
||||||
|
}
|
||||||
// Call the query failure callback
|
// Call the query failure callback
|
||||||
if (QueryFailed != null)
|
if (QueryFailed != null)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -109,6 +109,11 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
internal ConcurrentDictionary<string, Query> ActiveQueries => queries.Value;
|
internal ConcurrentDictionary<string, Query> ActiveQueries => queries.Value;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Internal task for testability
|
||||||
|
/// </summary>
|
||||||
|
internal Task WorkTask { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Instance of the connection service, used to get the connection info for a given owner URI
|
/// Instance of the connection service, used to get the connection info for a given owner URI
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -130,7 +135,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Holds a map from the simple execute unique GUID and the underlying task that is being ran
|
/// Holds a map from the simple execute unique GUID and the underlying task that is being ran
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly Lazy<ConcurrentDictionary<string, Task>> simpleExecuteRequests =
|
private readonly Lazy<ConcurrentDictionary<string, Task>> simpleExecuteRequests =
|
||||||
new Lazy<ConcurrentDictionary<string, Task>>(() => new ConcurrentDictionary<string, Task>());
|
new Lazy<ConcurrentDictionary<string, Task>>(() => new ConcurrentDictionary<string, Task>());
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -177,23 +182,34 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Handles request to execute a selection of a document in the workspace service
|
/// Handles request to execute a selection of a document in the workspace service
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal Task HandleExecuteRequest(ExecuteRequestParamsBase executeParams,
|
internal async Task HandleExecuteRequest(ExecuteRequestParamsBase executeParams,
|
||||||
RequestContext<ExecuteRequestResult> requestContext)
|
RequestContext<ExecuteRequestResult> requestContext)
|
||||||
{
|
{
|
||||||
// Setup actions to perform upon successful start and on failure to start
|
try
|
||||||
Func<Query, Task<bool>> queryCreateSuccessAction = async q => {
|
|
||||||
await requestContext.SendResult(new ExecuteRequestResult());
|
|
||||||
Logger.Write(TraceEventType.Stop, $"Response for Query: '{executeParams.OwnerUri} sent. Query Complete!");
|
|
||||||
return true;
|
|
||||||
};
|
|
||||||
Func<string, Task> queryCreateFailureAction = message =>
|
|
||||||
{
|
{
|
||||||
Logger.Write(TraceEventType.Warning, $"Failed to create Query: '{executeParams.OwnerUri}. Message: '{message}' Complete!");
|
// Setup actions to perform upon successful start and on failure to start
|
||||||
return requestContext.SendError(message);
|
Func<Query, Task<bool>> queryCreateSuccessAction = async q =>
|
||||||
};
|
{
|
||||||
|
await requestContext.SendResult(new ExecuteRequestResult());
|
||||||
|
Logger.Write(TraceEventType.Stop, $"Response for Query: '{executeParams.OwnerUri} sent. Query Complete!");
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
Func<string, Task> queryCreateFailureAction = message =>
|
||||||
|
{
|
||||||
|
Logger.Write(TraceEventType.Warning, $"Failed to create Query: '{executeParams.OwnerUri}. Message: '{message}' Complete!");
|
||||||
|
return requestContext.SendError(message);
|
||||||
|
};
|
||||||
|
|
||||||
// Use the internal handler to launch the query
|
// Use the internal handler to launch the query
|
||||||
return InterServiceExecuteQuery(executeParams, null, requestContext, queryCreateSuccessAction, queryCreateFailureAction, null, null);
|
WorkTask = Task.Run(async () =>
|
||||||
|
{
|
||||||
|
await InterServiceExecuteQuery(executeParams, null, requestContext, queryCreateSuccessAction, queryCreateFailureAction, null, null);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
await requestContext.SendError(ex.ToString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -219,14 +235,14 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
|||||||
await requestContext.SendError(SR.QueryServiceQueryInvalidOwnerUri);
|
await requestContext.SendError(SR.QueryServiceQueryInvalidOwnerUri);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ConnectParams connectParams = new ConnectParams
|
ConnectParams connectParams = new ConnectParams
|
||||||
{
|
{
|
||||||
OwnerUri = randomUri,
|
OwnerUri = randomUri,
|
||||||
Connection = connInfo.ConnectionDetails,
|
Connection = connInfo.ConnectionDetails,
|
||||||
Type = ConnectionType.Default
|
Type = ConnectionType.Default
|
||||||
};
|
};
|
||||||
|
|
||||||
Task workTask = Task.Run(async () => {
|
Task workTask = Task.Run(async () => {
|
||||||
await ConnectionService.Connect(connectParams);
|
await ConnectionService.Connect(connectParams);
|
||||||
|
|
||||||
@@ -243,26 +259,26 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
// check to make sure any results were recieved
|
// check to make sure any results were recieved
|
||||||
if (query.Batches.Length == 0
|
if (query.Batches.Length == 0
|
||||||
|| query.Batches[0].ResultSets.Count == 0)
|
|| query.Batches[0].ResultSets.Count == 0)
|
||||||
{
|
{
|
||||||
await requestContext.SendError(SR.QueryServiceResultSetHasNoResults);
|
await requestContext.SendError(SR.QueryServiceResultSetHasNoResults);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
long rowCount = query.Batches[0].ResultSets[0].RowCount;
|
long rowCount = query.Batches[0].ResultSets[0].RowCount;
|
||||||
// check to make sure there is a safe amount of rows to load into memory
|
// check to make sure there is a safe amount of rows to load into memory
|
||||||
if (rowCount > Int32.MaxValue)
|
if (rowCount > Int32.MaxValue)
|
||||||
{
|
{
|
||||||
await requestContext.SendError(SR.QueryServiceResultSetTooLarge);
|
await requestContext.SendError(SR.QueryServiceResultSetTooLarge);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SimpleExecuteResult result = new SimpleExecuteResult
|
SimpleExecuteResult result = new SimpleExecuteResult
|
||||||
{
|
{
|
||||||
RowCount = rowCount,
|
RowCount = rowCount,
|
||||||
ColumnInfo = query.Batches[0].ResultSets[0].Columns,
|
ColumnInfo = query.Batches[0].ResultSets[0].Columns,
|
||||||
Rows = new DbCellValue[0][]
|
Rows = new DbCellValue[0][]
|
||||||
};
|
};
|
||||||
|
|
||||||
if (rowCount > 0)
|
if (rowCount > 0)
|
||||||
@@ -280,8 +296,8 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
|||||||
result.Rows = subset.Rows;
|
result.Rows = subset.Rows;
|
||||||
}
|
}
|
||||||
await requestContext.SendResult(result);
|
await requestContext.SendResult(result);
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
Query removedQuery;
|
Query removedQuery;
|
||||||
Task removedTask;
|
Task removedTask;
|
||||||
@@ -306,7 +322,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
|||||||
|
|
||||||
ActiveSimpleExecuteRequests.TryAdd(randomUri, workTask);
|
ActiveSimpleExecuteRequests.TryAdd(randomUri, workTask);
|
||||||
}
|
}
|
||||||
catch(Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
await requestContext.SendError(ex.ToString());
|
await requestContext.SendError(ex.ToString());
|
||||||
}
|
}
|
||||||
@@ -335,7 +351,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Handles a request to get an execution plan
|
/// Handles a request to get an execution plan
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal async Task HandleExecutionPlanRequest(QueryExecutionPlanParams planParams,
|
internal async Task HandleExecutionPlanRequest(QueryExecutionPlanParams planParams,
|
||||||
@@ -502,17 +518,17 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
|||||||
/// <param name="queryFailureFunc">
|
/// <param name="queryFailureFunc">
|
||||||
/// Callback to call when query has completed execution with errors. May be <c>null</c>.
|
/// Callback to call when query has completed execution with errors. May be <c>null</c>.
|
||||||
/// </param>
|
/// </param>
|
||||||
public async Task InterServiceExecuteQuery(ExecuteRequestParamsBase executeParams,
|
public async Task InterServiceExecuteQuery(ExecuteRequestParamsBase executeParams,
|
||||||
ConnectionInfo connInfo,
|
ConnectionInfo connInfo,
|
||||||
IEventSender queryEventSender,
|
IEventSender queryEventSender,
|
||||||
Func<Query, Task<bool>> queryCreateSuccessFunc,
|
Func<Query, Task<bool>> queryCreateSuccessFunc,
|
||||||
Func<string, Task> queryCreateFailFunc,
|
Func<string, Task> queryCreateFailFunc,
|
||||||
Query.QueryAsyncEventHandler querySuccessFunc,
|
Query.QueryAsyncEventHandler querySuccessFunc,
|
||||||
Query.QueryAsyncErrorEventHandler queryFailureFunc)
|
Query.QueryAsyncErrorEventHandler queryFailureFunc)
|
||||||
{
|
{
|
||||||
Validate.IsNotNull(nameof(executeParams), executeParams);
|
Validate.IsNotNull(nameof(executeParams), executeParams);
|
||||||
Validate.IsNotNull(nameof(queryEventSender), queryEventSender);
|
Validate.IsNotNull(nameof(queryEventSender), queryEventSender);
|
||||||
|
|
||||||
Query newQuery;
|
Query newQuery;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -622,7 +638,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
|||||||
// if any oldQuery exists on the executeParams.OwnerUri but it has not yet executed,
|
// if any oldQuery exists on the executeParams.OwnerUri but it has not yet executed,
|
||||||
// then shouldn't we cancel and clean out that query since we are about to create a new query object on the current OwnerUri.
|
// then shouldn't we cancel and clean out that query since we are about to create a new query object on the current OwnerUri.
|
||||||
//
|
//
|
||||||
if (ActiveQueries.TryGetValue(executeParams.OwnerUri, out oldQuery) && oldQuery.HasExecuted)
|
if (ActiveQueries.TryGetValue(executeParams.OwnerUri, out oldQuery) && (oldQuery.HasExecuted || oldQuery.HasCancelled))
|
||||||
{
|
{
|
||||||
oldQuery.Dispose();
|
oldQuery.Dispose();
|
||||||
ActiveQueries.TryRemove(executeParams.OwnerUri, out oldQuery);
|
ActiveQueries.TryRemove(executeParams.OwnerUri, out oldQuery);
|
||||||
@@ -815,7 +831,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
|||||||
return GetSqlTextFromSelectionData(docRequest.OwnerUri, docRequest.QuerySelection);
|
return GetSqlTextFromSelectionData(docRequest.OwnerUri, docRequest.QuerySelection);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If it is a document statement, we'll retrieve the text from the document
|
// If it is a document statement, we'll retrieve the text from the document
|
||||||
ExecuteDocumentStatementParams stmtRequest = request as ExecuteDocumentStatementParams;
|
ExecuteDocumentStatementParams stmtRequest = request as ExecuteDocumentStatementParams;
|
||||||
if (stmtRequest != null)
|
if (stmtRequest != null)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -4,6 +4,8 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.SqlTools.ServiceLayer.Connection;
|
||||||
|
using Microsoft.SqlTools.ServiceLayer.QueryExecution;
|
||||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
||||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts.ExecuteRequests;
|
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts.ExecuteRequests;
|
||||||
using Microsoft.SqlTools.ServiceLayer.SqlContext;
|
using Microsoft.SqlTools.ServiceLayer.SqlContext;
|
||||||
@@ -29,6 +31,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution
|
|||||||
var executeRequest = RequestContextMocks.Create<ExecuteRequestResult>(null);
|
var executeRequest = RequestContextMocks.Create<ExecuteRequestResult>(null);
|
||||||
|
|
||||||
await queryService.HandleExecuteRequest(executeParams, executeRequest.Object);
|
await queryService.HandleExecuteRequest(executeParams, executeRequest.Object);
|
||||||
|
await queryService.WorkTask;
|
||||||
await queryService.ActiveQueries[Constants.OwnerUri].ExecutionTask;
|
await queryService.ActiveQueries[Constants.OwnerUri].ExecutionTask;
|
||||||
queryService.ActiveQueries[Constants.OwnerUri].HasExecuted = false; // Fake that it hasn't completed execution
|
queryService.ActiveQueries[Constants.OwnerUri].HasExecuted = false; // Fake that it hasn't completed execution
|
||||||
|
|
||||||
@@ -42,8 +45,9 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution
|
|||||||
await queryService.HandleCancelRequest(cancelParams, cancelRequest.Object);
|
await queryService.HandleCancelRequest(cancelParams, cancelRequest.Object);
|
||||||
|
|
||||||
// Then:
|
// Then:
|
||||||
// ... The query should not have been disposed
|
// ... The query should not have been disposed but should have been cancelled
|
||||||
Assert.Equal(1, queryService.ActiveQueries.Count);
|
Assert.Equal(1, queryService.ActiveQueries.Count);
|
||||||
|
Assert.Equal(true, queryService.ActiveQueries[Constants.OwnerUri].HasCancelled);
|
||||||
cancelRequest.Validate();
|
cancelRequest.Validate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,6 +62,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution
|
|||||||
var executeRequest = RequestContextMocks.Create<ExecuteRequestResult>(null);
|
var executeRequest = RequestContextMocks.Create<ExecuteRequestResult>(null);
|
||||||
|
|
||||||
await queryService.HandleExecuteRequest(executeParams, executeRequest.Object);
|
await queryService.HandleExecuteRequest(executeParams, executeRequest.Object);
|
||||||
|
await queryService.WorkTask;
|
||||||
await queryService.ActiveQueries[Constants.OwnerUri].ExecutionTask;
|
await queryService.ActiveQueries[Constants.OwnerUri].ExecutionTask;
|
||||||
|
|
||||||
// ... And then I request to cancel the query
|
// ... And then I request to cancel the query
|
||||||
@@ -71,8 +76,9 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution
|
|||||||
await queryService.HandleCancelRequest(cancelParams, cancelRequest.Object);
|
await queryService.HandleCancelRequest(cancelParams, cancelRequest.Object);
|
||||||
|
|
||||||
// Then:
|
// Then:
|
||||||
// ... The query should not have been disposed
|
// ... The query should not have been disposed and cancel should not have excecuted
|
||||||
Assert.NotEmpty(queryService.ActiveQueries);
|
Assert.NotEmpty(queryService.ActiveQueries);
|
||||||
|
Assert.Equal(false, queryService.ActiveQueries[Constants.OwnerUri].HasCancelled);
|
||||||
cancelRequest.Validate();
|
cancelRequest.Validate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,5 +99,40 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution
|
|||||||
await queryService.HandleCancelRequest(cancelParams, cancelRequest.Object);
|
await queryService.HandleCancelRequest(cancelParams, cancelRequest.Object);
|
||||||
cancelRequest.Validate();
|
cancelRequest.Validate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task CancelQueryBeforeExecutionStartedTest()
|
||||||
|
{
|
||||||
|
// Setup query settings
|
||||||
|
QueryExecutionSettings querySettings = new QueryExecutionSettings
|
||||||
|
{
|
||||||
|
ExecutionPlanOptions = new ExecutionPlanOptions
|
||||||
|
{
|
||||||
|
IncludeActualExecutionPlanXml = false,
|
||||||
|
IncludeEstimatedExecutionPlanXml = true
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Create query with a failure callback function
|
||||||
|
ConnectionInfo ci = Common.CreateTestConnectionInfo(null, false, false);
|
||||||
|
ConnectionService.Instance.OwnerToConnectionMap[ci.OwnerUri] = ci;
|
||||||
|
Query query = new Query(Constants.StandardQuery, ci, querySettings, MemoryFileSystem.GetFileStreamFactory());
|
||||||
|
|
||||||
|
string errorMessage = null;
|
||||||
|
Query.QueryAsyncErrorEventHandler failureCallback = async (q, e) =>
|
||||||
|
{
|
||||||
|
errorMessage = "Error Occured";
|
||||||
|
};
|
||||||
|
query.QueryFailed += failureCallback;
|
||||||
|
|
||||||
|
query.Cancel();
|
||||||
|
query.Execute();
|
||||||
|
await query.ExecutionTask;
|
||||||
|
|
||||||
|
// Validate that query has not been executed but cancelled and query failed called function was called
|
||||||
|
Assert.Equal(true, query.HasCancelled);
|
||||||
|
Assert.Equal(false, query.HasExecuted);
|
||||||
|
Assert.Equal("Error Occured", errorMessage);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -183,6 +183,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution
|
|||||||
HostingProtocol.RequestContext<ExecuteRequestResult> requestContext)
|
HostingProtocol.RequestContext<ExecuteRequestResult> requestContext)
|
||||||
{
|
{
|
||||||
await service.HandleExecuteRequest(qeParams, requestContext);
|
await service.HandleExecuteRequest(qeParams, requestContext);
|
||||||
|
await service.WorkTask;
|
||||||
if (service.ActiveQueries.ContainsKey(qeParams.OwnerUri) && service.ActiveQueries[qeParams.OwnerUri].ExecutionTask != null)
|
if (service.ActiveQueries.ContainsKey(qeParams.OwnerUri) && service.ActiveQueries[qeParams.OwnerUri].ExecutionTask != null)
|
||||||
{
|
{
|
||||||
await service.ActiveQueries[qeParams.OwnerUri].ExecutionTask;
|
await service.ActiveQueries[qeParams.OwnerUri].ExecutionTask;
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution
|
|||||||
var executeParams = new ExecuteDocumentSelectionParams {QuerySelection = null, OwnerUri = Constants.OwnerUri};
|
var executeParams = new ExecuteDocumentSelectionParams {QuerySelection = null, OwnerUri = Constants.OwnerUri};
|
||||||
var executeRequest = RequestContextMocks.Create<ExecuteRequestResult>(null);
|
var executeRequest = RequestContextMocks.Create<ExecuteRequestResult>(null);
|
||||||
await queryService.HandleExecuteRequest(executeParams, executeRequest.Object);
|
await queryService.HandleExecuteRequest(executeParams, executeRequest.Object);
|
||||||
|
await queryService.WorkTask;
|
||||||
await queryService.ActiveQueries[Constants.OwnerUri].ExecutionTask;
|
await queryService.ActiveQueries[Constants.OwnerUri].ExecutionTask;
|
||||||
|
|
||||||
// ... And then I dispose of the query
|
// ... And then I dispose of the query
|
||||||
@@ -90,6 +91,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution
|
|||||||
var queryParams = new ExecuteDocumentSelectionParams { QuerySelection = Common.WholeDocument, OwnerUri = Constants.OwnerUri };
|
var queryParams = new ExecuteDocumentSelectionParams { QuerySelection = Common.WholeDocument, OwnerUri = Constants.OwnerUri };
|
||||||
var requestContext = RequestContextMocks.Create<ExecuteRequestResult>(null);
|
var requestContext = RequestContextMocks.Create<ExecuteRequestResult>(null);
|
||||||
await queryService.HandleExecuteRequest(queryParams, requestContext.Object);
|
await queryService.HandleExecuteRequest(queryParams, requestContext.Object);
|
||||||
|
await queryService.WorkTask;
|
||||||
await queryService.ActiveQueries[Constants.OwnerUri].ExecutionTask;
|
await queryService.ActiveQueries[Constants.OwnerUri].ExecutionTask;
|
||||||
|
|
||||||
// ... And it sticks around as an active query
|
// ... And it sticks around as an active query
|
||||||
|
|||||||
@@ -152,6 +152,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution
|
|||||||
};
|
};
|
||||||
var executeRequest = RequestContextMocks.Create<ExecuteRequestResult>(null);
|
var executeRequest = RequestContextMocks.Create<ExecuteRequestResult>(null);
|
||||||
await queryService.HandleExecuteRequest(executeParams, executeRequest.Object);
|
await queryService.HandleExecuteRequest(executeParams, executeRequest.Object);
|
||||||
|
await queryService.WorkTask;
|
||||||
await queryService.ActiveQueries[Constants.OwnerUri].ExecutionTask;
|
await queryService.ActiveQueries[Constants.OwnerUri].ExecutionTask;
|
||||||
|
|
||||||
// ... And I then ask for a valid execution plan
|
// ... And I then ask for a valid execution plan
|
||||||
@@ -201,6 +202,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution
|
|||||||
};
|
};
|
||||||
var executeRequest = RequestContextMocks.Create<ExecuteRequestResult>(null);
|
var executeRequest = RequestContextMocks.Create<ExecuteRequestResult>(null);
|
||||||
await queryService.HandleExecuteRequest(executeParams, executeRequest.Object);
|
await queryService.HandleExecuteRequest(executeParams, executeRequest.Object);
|
||||||
|
await queryService.WorkTask;
|
||||||
await queryService.ActiveQueries[Constants.OwnerUri].ExecutionTask;
|
await queryService.ActiveQueries[Constants.OwnerUri].ExecutionTask;
|
||||||
queryService.ActiveQueries[Constants.OwnerUri].Batches[0].ResultSets[0].hasStartedRead = false;
|
queryService.ActiveQueries[Constants.OwnerUri].Batches[0].ResultSets[0].hasStartedRead = false;
|
||||||
|
|
||||||
@@ -232,6 +234,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution
|
|||||||
};
|
};
|
||||||
var executeRequest = RequestContextMocks.Create<ExecuteRequestResult>(null);
|
var executeRequest = RequestContextMocks.Create<ExecuteRequestResult>(null);
|
||||||
await queryService.HandleExecuteRequest(executeParams, executeRequest.Object);
|
await queryService.HandleExecuteRequest(executeParams, executeRequest.Object);
|
||||||
|
await queryService.WorkTask;
|
||||||
await queryService.ActiveQueries[Constants.OwnerUri].ExecutionTask;
|
await queryService.ActiveQueries[Constants.OwnerUri].ExecutionTask;
|
||||||
|
|
||||||
// ... And I then ask for an execution plan from a result set
|
// ... And I then ask for an execution plan from a result set
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.SaveResults
|
|||||||
var executeParams = new ExecuteDocumentSelectionParams { QuerySelection = null, OwnerUri = Constants.OwnerUri };
|
var executeParams = new ExecuteDocumentSelectionParams { QuerySelection = null, OwnerUri = Constants.OwnerUri };
|
||||||
var executeRequest = RequestContextMocks.Create<ExecuteRequestResult>(null);
|
var executeRequest = RequestContextMocks.Create<ExecuteRequestResult>(null);
|
||||||
await qes.HandleExecuteRequest(executeParams, executeRequest.Object);
|
await qes.HandleExecuteRequest(executeParams, executeRequest.Object);
|
||||||
|
await qes.WorkTask;
|
||||||
await qes.ActiveQueries[Constants.OwnerUri].ExecutionTask;
|
await qes.ActiveQueries[Constants.OwnerUri].ExecutionTask;
|
||||||
|
|
||||||
// If: I attempt to save a result set and get it to throw because of invalid column selection
|
// If: I attempt to save a result set and get it to throw because of invalid column selection
|
||||||
@@ -106,6 +107,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.SaveResults
|
|||||||
var executeParams = new ExecuteDocumentSelectionParams {QuerySelection = null, OwnerUri = Constants.OwnerUri};
|
var executeParams = new ExecuteDocumentSelectionParams {QuerySelection = null, OwnerUri = Constants.OwnerUri};
|
||||||
var executeRequest = RequestContextMocks.Create<ExecuteRequestResult>(null);
|
var executeRequest = RequestContextMocks.Create<ExecuteRequestResult>(null);
|
||||||
await qes.HandleExecuteRequest(executeParams, executeRequest.Object);
|
await qes.HandleExecuteRequest(executeParams, executeRequest.Object);
|
||||||
|
await qes.WorkTask;
|
||||||
await qes.ActiveQueries[Constants.OwnerUri].ExecutionTask;
|
await qes.ActiveQueries[Constants.OwnerUri].ExecutionTask;
|
||||||
|
|
||||||
// If: I attempt to save a result set from a query
|
// If: I attempt to save a result set from a query
|
||||||
@@ -173,6 +175,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.SaveResults
|
|||||||
var executeParams = new ExecuteDocumentSelectionParams { QuerySelection = null, OwnerUri = Constants.OwnerUri };
|
var executeParams = new ExecuteDocumentSelectionParams { QuerySelection = null, OwnerUri = Constants.OwnerUri };
|
||||||
var executeRequest = RequestContextMocks.Create<ExecuteRequestResult>(null);
|
var executeRequest = RequestContextMocks.Create<ExecuteRequestResult>(null);
|
||||||
await qes.HandleExecuteRequest(executeParams, executeRequest.Object);
|
await qes.HandleExecuteRequest(executeParams, executeRequest.Object);
|
||||||
|
await qes.WorkTask;
|
||||||
await qes.ActiveQueries[Constants.OwnerUri].ExecutionTask;
|
await qes.ActiveQueries[Constants.OwnerUri].ExecutionTask;
|
||||||
|
|
||||||
// If: I attempt to save a result set and get it to throw because of invalid column selection
|
// If: I attempt to save a result set and get it to throw because of invalid column selection
|
||||||
@@ -216,6 +219,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.SaveResults
|
|||||||
var executeParams = new ExecuteDocumentSelectionParams { QuerySelection = null, OwnerUri = Constants.OwnerUri };
|
var executeParams = new ExecuteDocumentSelectionParams { QuerySelection = null, OwnerUri = Constants.OwnerUri };
|
||||||
var executeRequest = RequestContextMocks.Create<ExecuteRequestResult>(null);
|
var executeRequest = RequestContextMocks.Create<ExecuteRequestResult>(null);
|
||||||
await qes.HandleExecuteRequest(executeParams, executeRequest.Object);
|
await qes.HandleExecuteRequest(executeParams, executeRequest.Object);
|
||||||
|
await qes.WorkTask;
|
||||||
await qes.ActiveQueries[Constants.OwnerUri].ExecutionTask;
|
await qes.ActiveQueries[Constants.OwnerUri].ExecutionTask;
|
||||||
|
|
||||||
// If: I attempt to save a result set from a query
|
// If: I attempt to save a result set from a query
|
||||||
@@ -282,6 +286,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.SaveResults
|
|||||||
var executeParams = new ExecuteDocumentSelectionParams {QuerySelection = null, OwnerUri = Constants.OwnerUri};
|
var executeParams = new ExecuteDocumentSelectionParams {QuerySelection = null, OwnerUri = Constants.OwnerUri};
|
||||||
var executeRequest = RequestContextMocks.Create<ExecuteRequestResult>(null);
|
var executeRequest = RequestContextMocks.Create<ExecuteRequestResult>(null);
|
||||||
await qes.HandleExecuteRequest(executeParams, executeRequest.Object);
|
await qes.HandleExecuteRequest(executeParams, executeRequest.Object);
|
||||||
|
await qes.WorkTask;
|
||||||
await qes.ActiveQueries[Constants.OwnerUri].ExecutionTask;
|
await qes.ActiveQueries[Constants.OwnerUri].ExecutionTask;
|
||||||
|
|
||||||
// If: I attempt to save a result set and get it to throw because of invalid column selection
|
// If: I attempt to save a result set and get it to throw because of invalid column selection
|
||||||
@@ -325,6 +330,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.SaveResults
|
|||||||
var executeParams = new ExecuteDocumentSelectionParams {QuerySelection = null, OwnerUri = Constants.OwnerUri};
|
var executeParams = new ExecuteDocumentSelectionParams {QuerySelection = null, OwnerUri = Constants.OwnerUri};
|
||||||
var executeRequest = RequestContextMocks.Create<ExecuteRequestResult>(null);
|
var executeRequest = RequestContextMocks.Create<ExecuteRequestResult>(null);
|
||||||
await qes.HandleExecuteRequest(executeParams, executeRequest.Object);
|
await qes.HandleExecuteRequest(executeParams, executeRequest.Object);
|
||||||
|
await qes.WorkTask;
|
||||||
await qes.ActiveQueries[Constants.OwnerUri].ExecutionTask;
|
await qes.ActiveQueries[Constants.OwnerUri].ExecutionTask;
|
||||||
|
|
||||||
// If: I attempt to save a result set from a query
|
// If: I attempt to save a result set from a query
|
||||||
@@ -393,6 +399,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.SaveResults
|
|||||||
var executeParams = new ExecuteDocumentSelectionParams { QuerySelection = null, OwnerUri = Constants.OwnerUri };
|
var executeParams = new ExecuteDocumentSelectionParams { QuerySelection = null, OwnerUri = Constants.OwnerUri };
|
||||||
var executeRequest = RequestContextMocks.Create<ExecuteRequestResult>(null);
|
var executeRequest = RequestContextMocks.Create<ExecuteRequestResult>(null);
|
||||||
await qes.HandleExecuteRequest(executeParams, executeRequest.Object);
|
await qes.HandleExecuteRequest(executeParams, executeRequest.Object);
|
||||||
|
await qes.WorkTask;
|
||||||
await qes.ActiveQueries[Constants.OwnerUri].ExecutionTask;
|
await qes.ActiveQueries[Constants.OwnerUri].ExecutionTask;
|
||||||
|
|
||||||
// If: I attempt to save a result set and get it to throw because of invalid column selection
|
// If: I attempt to save a result set and get it to throw because of invalid column selection
|
||||||
@@ -436,6 +443,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.SaveResults
|
|||||||
var executeParams = new ExecuteDocumentSelectionParams { QuerySelection = null, OwnerUri = Constants.OwnerUri };
|
var executeParams = new ExecuteDocumentSelectionParams { QuerySelection = null, OwnerUri = Constants.OwnerUri };
|
||||||
var executeRequest = RequestContextMocks.Create<ExecuteRequestResult>(null);
|
var executeRequest = RequestContextMocks.Create<ExecuteRequestResult>(null);
|
||||||
await qes.HandleExecuteRequest(executeParams, executeRequest.Object);
|
await qes.HandleExecuteRequest(executeParams, executeRequest.Object);
|
||||||
|
await qes.WorkTask;
|
||||||
await qes.ActiveQueries[Constants.OwnerUri].ExecutionTask;
|
await qes.ActiveQueries[Constants.OwnerUri].ExecutionTask;
|
||||||
|
|
||||||
// If: I attempt to save a result set from a query
|
// If: I attempt to save a result set from a query
|
||||||
|
|||||||
@@ -140,6 +140,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution
|
|||||||
var executeParams = new ExecuteDocumentSelectionParams {QuerySelection = null, OwnerUri = Constants.OwnerUri};
|
var executeParams = new ExecuteDocumentSelectionParams {QuerySelection = null, OwnerUri = Constants.OwnerUri};
|
||||||
var executeRequest = RequestContextMocks.Create<ExecuteRequestResult>(null);
|
var executeRequest = RequestContextMocks.Create<ExecuteRequestResult>(null);
|
||||||
await queryService.HandleExecuteRequest(executeParams, executeRequest.Object);
|
await queryService.HandleExecuteRequest(executeParams, executeRequest.Object);
|
||||||
|
await queryService.WorkTask;
|
||||||
await queryService.ActiveQueries[Constants.OwnerUri].ExecutionTask;
|
await queryService.ActiveQueries[Constants.OwnerUri].ExecutionTask;
|
||||||
|
|
||||||
// ... And I then ask for a valid set of results from it
|
// ... And I then ask for a valid set of results from it
|
||||||
@@ -179,6 +180,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution
|
|||||||
var executeParams = new ExecuteDocumentSelectionParams { QuerySelection = null, OwnerUri = Constants.OwnerUri };
|
var executeParams = new ExecuteDocumentSelectionParams { QuerySelection = null, OwnerUri = Constants.OwnerUri };
|
||||||
var executeRequest = RequestContextMocks.Create<ExecuteRequestResult>(null);
|
var executeRequest = RequestContextMocks.Create<ExecuteRequestResult>(null);
|
||||||
await queryService.HandleExecuteRequest(executeParams, executeRequest.Object);
|
await queryService.HandleExecuteRequest(executeParams, executeRequest.Object);
|
||||||
|
await queryService.WorkTask;
|
||||||
await queryService.ActiveQueries[Constants.OwnerUri].ExecutionTask;
|
await queryService.ActiveQueries[Constants.OwnerUri].ExecutionTask;
|
||||||
queryService.ActiveQueries[Constants.OwnerUri].Batches[0].ResultSets[0].hasStartedRead = false;
|
queryService.ActiveQueries[Constants.OwnerUri].Batches[0].ResultSets[0].hasStartedRead = false;
|
||||||
|
|
||||||
@@ -201,6 +203,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution
|
|||||||
var executeParams = new ExecuteDocumentSelectionParams { QuerySelection = null, OwnerUri = Constants.OwnerUri };
|
var executeParams = new ExecuteDocumentSelectionParams { QuerySelection = null, OwnerUri = Constants.OwnerUri };
|
||||||
var executeRequest = RequestContextMocks.Create<ExecuteRequestResult>(null);
|
var executeRequest = RequestContextMocks.Create<ExecuteRequestResult>(null);
|
||||||
await queryService.HandleExecuteRequest(executeParams, executeRequest.Object);
|
await queryService.HandleExecuteRequest(executeParams, executeRequest.Object);
|
||||||
|
await queryService.WorkTask;
|
||||||
await queryService.ActiveQueries[Constants.OwnerUri].ExecutionTask;
|
await queryService.ActiveQueries[Constants.OwnerUri].ExecutionTask;
|
||||||
|
|
||||||
// ... And I then ask for a set of results from it
|
// ... And I then ask for a set of results from it
|
||||||
|
|||||||
Reference in New Issue
Block a user