Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 23 additions & 8 deletions tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,17 +141,32 @@ public async Task Decode_IsCancellable(string fileName, int cancellationDelayMs)
TestEnvironment.InputImagesDirectoryFullPath,
fileName);

var cts = new CancellationTokenSource();
if (cancellationDelayMs == 0)
{
cts.Cancel();
}
else
const int NumberOfRuns = 5;

for (int i = 0; i < NumberOfRuns; i++)
{
cts.CancelAfter(cancellationDelayMs);
var cts = new CancellationTokenSource();
if (cancellationDelayMs == 0)
{
cts.Cancel();
}
else
{
cts.CancelAfter(cancellationDelayMs);
}

try
{
using var image = await Image.LoadAsync(hugeFile, cts.Token);
}
catch (TaskCanceledException)
{
// Succesfully observed a cancellation
return;
}
}

await Assert.ThrowsAsync<TaskCanceledException>(() => Image.LoadAsync(hugeFile, cts.Token));
throw new Exception($"No cancellation happened out of {NumberOfRuns} runs!");
}

[Theory(Skip = "Identify is too fast, doesn't work reliably.")]
Expand Down