Skip to content

Commit cf9496d

Browse files
committed
test allocation limits
1 parent 3d298db commit cf9496d

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

tests/ImageSharp.Tests/Memory/Allocators/UniformUnmanagedPoolMemoryAllocatorTests.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,30 @@ private static void AllocateSingleAndForget(UniformUnmanagedMemoryPoolMemoryAllo
398398
}
399399
}
400400

401+
[Fact]
402+
public void Allocate_OverLimit_ThrowsInvalidMemoryOperationException()
403+
{
404+
MemoryAllocator allocator = MemoryAllocator.Create(new MemoryAllocatorOptions()
405+
{
406+
AllocationLimitMegabytes = 4
407+
});
408+
const int oneMb = 1 << 20;
409+
allocator.Allocate<byte>(4 * oneMb).Dispose(); // Should work
410+
Assert.Throws<InvalidMemoryOperationException>(() => allocator.Allocate<byte>(5 * oneMb));
411+
}
412+
413+
[Fact]
414+
public void AllocateGroup_OverLimit_ThrowsInvalidMemoryOperationException()
415+
{
416+
MemoryAllocator allocator = MemoryAllocator.Create(new MemoryAllocatorOptions()
417+
{
418+
AllocationLimitMegabytes = 4
419+
});
420+
const int oneMb = 1 << 20;
421+
allocator.AllocateGroup<byte>(4 * oneMb, 1024).Dispose(); // Should work
422+
Assert.Throws<InvalidMemoryOperationException>(() => allocator.AllocateGroup<byte>(5 * oneMb, 1024));
423+
}
424+
401425
#if NETCOREAPP3_1_OR_GREATER
402426
[Fact]
403427
public void Issue2001_NegativeMemoryReportedByGc()

0 commit comments

Comments
 (0)