Skip to content

Commit

Permalink
Tests some internals.
Browse files Browse the repository at this point in the history
Increase overall coverage.
  • Loading branch information
tommasobertoni committed Jan 23, 2021
1 parent 399f956 commit 2a2f858
Showing 1 changed file with 38 additions and 0 deletions.
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);
}
}
}

0 comments on commit 2a2f858

Please sign in to comment.