mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-24 17:24:14 -05:00
Query Execution: Better exception handling on unawaited async tasks (#502)
* WIP * This code makes it work! * Adding similar exception hanling behavior to saving result sets * Adding unit tests for new extension methods Auto-cleanup of proj file whitespace * Implementing changes as per code review comments
This commit is contained in:
@@ -2,8 +2,8 @@
|
||||
<PropertyGroup Label="Configuration">
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp2.0</TargetFramework>
|
||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||
<DefineConstants>$(DefineConstants);NETCOREAPP1_0</DefineConstants>
|
||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||
<DefineConstants>$(DefineConstants);NETCOREAPP1_0</DefineConstants>
|
||||
<IsPackable>false</IsPackable>
|
||||
<ApplicationIcon />
|
||||
<StartupObject />
|
||||
@@ -12,10 +12,10 @@
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />
|
||||
<PackageReference Include="xunit" Version="2.2.0" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
|
||||
<PackageReference Include="System.Data.SqlClient" Version="4.4.0" />
|
||||
<PackageReference Include="Microsoft.SqlServer.Smo" Version="140.2.6" />
|
||||
<PackageReference Include="System.Data.SqlClient" Version="4.4.0" />
|
||||
<PackageReference Include="Microsoft.SqlServer.Smo" Version="140.2.6" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Newtonsoft.Json">
|
||||
<HintPath>../../bin/ref/Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
@@ -39,4 +39,4 @@
|
||||
<ItemGroup>
|
||||
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
@@ -0,0 +1,53 @@
|
||||
//
|
||||
// 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.Threading.Tasks;
|
||||
using Microsoft.SqlTools.ServiceLayer.Utility;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Utility
|
||||
{
|
||||
public class TaskExtensionTests
|
||||
{
|
||||
[Fact]
|
||||
public async Task ContinueWithOnFaultedNullContinuation()
|
||||
{
|
||||
// Setup: Create a task that will definitely fault
|
||||
Task failureTask = new Task(() => throw new Exception("It fail!"));
|
||||
|
||||
// If: I continue on fault and start the task
|
||||
Task continuationTask = failureTask.ContinueWithOnFaulted(null);
|
||||
failureTask.Start();
|
||||
await continuationTask;
|
||||
|
||||
// Then: The task should have completed without fault
|
||||
Assert.Equal(TaskStatus.RanToCompletion, continuationTask.Status);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ContinueWithOnFaultedContinuatation()
|
||||
{
|
||||
// Setup:
|
||||
// ... Create a new task that will definitely fault
|
||||
Task failureTask = new Task(() => throw new Exception("It fail!"));
|
||||
|
||||
// ... Create a quick continuation task that will signify if it's been called
|
||||
Task providedTask = null;
|
||||
|
||||
// If: I continue on fault, with a continuation task
|
||||
Task continuationTask = failureTask.ContinueWithOnFaulted(task => { providedTask = task; });
|
||||
failureTask.Start();
|
||||
await continuationTask;
|
||||
|
||||
// Then:
|
||||
// ... The task should have completed without fault
|
||||
Assert.Equal(TaskStatus.RanToCompletion, continuationTask.Status);
|
||||
|
||||
// ... The continuation action should have been called with the original failure task
|
||||
Assert.Equal(failureTask, providedTask);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user