Browse Source

re-create add original DecodeAsync_IsCancellable test

pull/2301/head
Anton Firszov 4 years ago
parent
commit
00ca204c3d
  1. 20
      tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs

20
tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs

@ -251,16 +251,26 @@ public partial class JpegDecoderTests
Assert.IsType<InvalidMemoryOperationException>(ex.InnerException);
}
[Fact]
public async Task DecodeAsync_IsCancellable()
[Theory]
[InlineData(0)]
[InlineData(0.5)]
[InlineData(0.9)]
public async Task DecodeAsync_IsCancellable(double percentageOfStreamReadToCancel)
{
var cts = new CancellationTokenSource();
string file = Path.Combine(TestEnvironment.InputImagesDirectoryFullPath, TestImages.Jpeg.Baseline.Jpeg420Small);
using var pausedStream = new PausedStream(file);
pausedStream.OnWaiting(_ =>
pausedStream.OnWaiting(s =>
{
cts.Cancel();
pausedStream.Release();
if (s.Position >= s.Length * percentageOfStreamReadToCancel)
{
cts.Cancel();
pausedStream.Release();
}
else
{
pausedStream.Next();
}
});
var configuration = Configuration.CreateDefaultInstance();

Loading…
Cancel
Save