Skip to content

CompleteWithinAsync fails for canceled Tasks #2833

@shuebner

Description

@shuebner

Description

When cancelling a task and then asserting its completion with CompleteWithinAsync, 6.12.0 works fine, 6.12.1 throws OperationCanceledException and thus fails the test.

I realize that this was probably deliberately done in #2614 .

However, this is a breaking change in a patch version increase and thus a violation of semver.

Reproduction Steps

[Fact]
public async Task When_cancellation_token_is_cancelled_Then_returns_immediately2()
{
  var pulse = new PeriodicTimer(TimeSpan.FromMinutes(1));
  using CancellationTokenSource cts = new();

  var waitForPulseTask = pulse.WaitForNextTickAsync(cts.Token);
  waitForPulseTask.IsCompleted.Should().BeFalse();
  cts.Cancel();

  Func<Task> waitAction = () => waitForPulseTask.AsTask();
  await waitAction.Should().CompleteWithinAsync(TimeSpan.FromMilliseconds(100));
  waitForPulseTask.IsCanceled.Should().BeTrue();
}

Expected behavior

Assertion behavior is consistent between patch versions

Actual behavior

Assertion behavior changed from pass to fail between patch versions.

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

Are you willing to help with a pull-request?

No

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions