Skip to content

DownloadFileTaskAsync not throwing an OperationCanceledException when CancellationToken is canceled #203

@Otiel

Description

@Otiel

When passing a CancellationToken to DownloadFileTaskAsync, I'm expecting the method to throw an OperationCanceledException if the cancellation has been requested and the download is cancelled.

This would allow me to manage the cancellation properly later in my code.

This does not seem to be the case today: this test should not fail:

[Test]
public void RequestingCancellation_Throws_OperationCanceledException()
{
    // Arrange
    const string fileUrl = "https://www.examplefile.com/file-download/202"; // 1 GB txt file
    var cts = new CancellationTokenSource();
    cts.CancelAfter(500);

    Assert.ThrowsAsync<OperationCanceledException>(async () =>
    {
        // Act
        await _sut.DownloadFileTaskAsync(fileUrl, cts.Token);
    });
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions