-
Notifications
You must be signed in to change notification settings - Fork 263
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bugfix for CancellationTokenSource (#593)
* Bugfix for CancellationTokenSource Added initialization that was missing in the NetCoreTestContext and added a test to cover the net core scenario as well.
- Loading branch information
1 parent
249cc70
commit a208ab7
Showing
7 changed files
with
141 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
test/E2ETests/TestAssets/TimeoutTestProjectNetCore/SelfTerminatingTestClass.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
namespace TimeoutTestProject | ||
{ | ||
[TestClass] | ||
public class SelfTerminatingTestClass | ||
{ | ||
public TestContext TestContext { get; set; } | ||
|
||
[TestMethod] | ||
[Timeout(60000)] | ||
public void SelfTerminatingTestMethod() | ||
{ | ||
TestContext.CancellationTokenSource.Cancel(); | ||
} | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...ests/TestAssets/TimeoutTestProjectNetCore/TerimnateLongRunningTasksUsingTokenTestClass.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
namespace TimeoutTestProject | ||
{ | ||
[TestClass] | ||
public class TerimnateLongRunningTasksUsingTokenTestClass | ||
{ | ||
public TestContext TestContext { get; set; } | ||
|
||
[TestMethod] | ||
[Timeout(5000)] | ||
public void TerimnateLongRunningTasksUsingToken() | ||
{ | ||
var longTask = new Thread(ExecuteLong); | ||
longTask.Start(); | ||
longTask.Join(); | ||
} | ||
|
||
private void ExecuteLong() | ||
{ | ||
try | ||
{ | ||
File.Delete("TimeoutTestOutputNetCore.txt"); | ||
Task.Delay(100000).Wait(TestContext.CancellationTokenSource.Token); | ||
} | ||
catch (OperationCanceledException) | ||
{ | ||
File.WriteAllText("TimeoutTestOutputNetCore.txt", "Written from long running thread post termination"); | ||
} | ||
} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
test/E2ETests/TestAssets/TimeoutTestProjectNetCore/TimeoutTestProjectNetCore.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TestFxRoot Condition="$(TestFxRoot) == ''">..\..\..\..\</TestFxRoot> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp1.1</TargetFramework> | ||
<FrameworkIdentifier>NetCore</FrameworkIdentifier> | ||
<IsPackable>false</IsPackable> | ||
<!--<AppendTargetFrameworkToOutputPath>true</AppendTargetFrameworkToOutputPath>--> | ||
<OutputPath>$(TestFxRoot)artifacts\TestAssets\</OutputPath> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="$(TestFxRoot)\src\TestFramework\Extension.Core\Extension.Core.csproj" /> | ||
<ProjectReference Include="$(TestFxRoot)\src\TestFramework\MSTest.Core\MSTest.Core.csproj" /> | ||
</ItemGroup> | ||
</Project> |