Skip to content

Commit 572366e

Browse files
committed
test allocation limits
1 parent d1cc651 commit 572366e

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
@@ -418,4 +418,28 @@ static void RunTest()
418418
_ = MemoryAllocator.Create();
419419
}
420420
}
421+
422+
[Fact]
423+
public void Allocate_OverLimit_ThrowsInvalidMemoryOperationException()
424+
{
425+
MemoryAllocator allocator = MemoryAllocator.Create(new MemoryAllocatorOptions()
426+
{
427+
AllocationLimitMegabytes = 4
428+
});
429+
const int oneMb = 1 << 20;
430+
allocator.Allocate<byte>(4 * oneMb).Dispose(); // Should work
431+
Assert.Throws<InvalidMemoryOperationException>(() => allocator.Allocate<byte>(5 * oneMb));
432+
}
433+
434+
[Fact]
435+
public void AllocateGroup_OverLimit_ThrowsInvalidMemoryOperationException()
436+
{
437+
MemoryAllocator allocator = MemoryAllocator.Create(new MemoryAllocatorOptions()
438+
{
439+
AllocationLimitMegabytes = 4
440+
});
441+
const int oneMb = 1 << 20;
442+
allocator.AllocateGroup<byte>(4 * oneMb, 1024).Dispose(); // Should work
443+
Assert.Throws<InvalidMemoryOperationException>(() => allocator.AllocateGroup<byte>(5 * oneMb, 1024));
444+
}
421445
}

0 commit comments

Comments
 (0)