-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
1 changed file
with
38 additions
and
0 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
tests/NScatterGather.Tests/Internals/CancellationTokenTaskSourceTests.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,38 @@ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
namespace NScatterGather.Internals | ||
{ | ||
public class CancellationTokenTaskSourceTests | ||
{ | ||
[Fact] | ||
public void Task_is_immediately_canceled() | ||
{ | ||
var token = new CancellationToken(true); | ||
using var source = new CancellationTokenTaskSource<object>(token); | ||
Assert.True(source.Task.IsCanceled); | ||
} | ||
|
||
[Fact(Timeout = 5000)] | ||
public async Task Task_completes_after_expected_time() | ||
{ | ||
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(2)); | ||
using var source = new CancellationTokenTaskSource<object>(cts.Token); | ||
|
||
bool canceled = false; | ||
|
||
try | ||
{ | ||
await source.Task; | ||
} | ||
catch (TaskCanceledException) | ||
{ | ||
canceled = true; | ||
} | ||
|
||
Assert.True(canceled); | ||
} | ||
} | ||
} |