From e2c574856ed087e58f776d9f6a5f10ef87b72cf5 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Thu, 8 Dec 2022 15:26:40 +1000 Subject: [PATCH] Base the buffer size on the stream length --- .../ImageSharp.Tests/Image/ImageTests.Decode_Cancellation.cs | 2 +- tests/ImageSharp.Tests/TestUtilities/IPausedStream.cs | 2 ++ tests/ImageSharp.Tests/TestUtilities/PausedMemoryStream.cs | 4 ++-- tests/ImageSharp.Tests/TestUtilities/PausedStream.cs | 4 ++-- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/tests/ImageSharp.Tests/Image/ImageTests.Decode_Cancellation.cs b/tests/ImageSharp.Tests/Image/ImageTests.Decode_Cancellation.cs index 6b74e9b354..543dd28cd7 100644 --- a/tests/ImageSharp.Tests/Image/ImageTests.Decode_Cancellation.cs +++ b/tests/ImageSharp.Tests/Image/ImageTests.Decode_Cancellation.cs @@ -85,7 +85,7 @@ public partial class ImageTests Configuration configuration = Configuration.CreateDefaultInstance(); configuration.FileSystem = new SingleStreamFileSystem((Stream)pausedStream); - configuration.StreamProcessingBufferSize = 256; + configuration.StreamProcessingBufferSize = (int)Math.Min(128, pausedStream.Length / 4); DecoderOptions options = new() { diff --git a/tests/ImageSharp.Tests/TestUtilities/IPausedStream.cs b/tests/ImageSharp.Tests/TestUtilities/IPausedStream.cs index 1eedef9d09..ec9b2e7e17 100644 --- a/tests/ImageSharp.Tests/TestUtilities/IPausedStream.cs +++ b/tests/ImageSharp.Tests/TestUtilities/IPausedStream.cs @@ -12,4 +12,6 @@ public interface IPausedStream : IDisposable public void Next(); public void Release(); + + public long Length { get; } } diff --git a/tests/ImageSharp.Tests/TestUtilities/PausedMemoryStream.cs b/tests/ImageSharp.Tests/TestUtilities/PausedMemoryStream.cs index 5b285b4caa..ae4af24f14 100644 --- a/tests/ImageSharp.Tests/TestUtilities/PausedMemoryStream.cs +++ b/tests/ImageSharp.Tests/TestUtilities/PausedMemoryStream.cs @@ -12,9 +12,9 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities; /// public class PausedMemoryStream : MemoryStream, IPausedStream { - private readonly SemaphoreSlim semaphore = new SemaphoreSlim(0); + private readonly SemaphoreSlim semaphore = new(0); - private readonly CancellationTokenSource cancelationTokenSource = new CancellationTokenSource(); + private readonly CancellationTokenSource cancelationTokenSource = new(); private Action onWaitingCallback; diff --git a/tests/ImageSharp.Tests/TestUtilities/PausedStream.cs b/tests/ImageSharp.Tests/TestUtilities/PausedStream.cs index 8af168d67f..3c780f3474 100644 --- a/tests/ImageSharp.Tests/TestUtilities/PausedStream.cs +++ b/tests/ImageSharp.Tests/TestUtilities/PausedStream.cs @@ -7,9 +7,9 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities; public class PausedStream : Stream, IPausedStream { - private readonly SemaphoreSlim semaphore = new SemaphoreSlim(0); + private readonly SemaphoreSlim semaphore = new(0); - private readonly CancellationTokenSource cancelationTokenSource = new CancellationTokenSource(); + private readonly CancellationTokenSource cancelationTokenSource = new(); private readonly Stream innerStream; private Action onWaitingCallback;