Skip to content

Commit 168c01d

Browse files
committed
move RentReturnRelease_SubsequentRentReturnsDifferentHandles out of process
1 parent 3ca5c37 commit 168c01d

File tree

1 file changed

+32
-27
lines changed

1 file changed

+32
-27
lines changed

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

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -253,35 +253,40 @@ public void Rent_MultiBuff_BelowCapacity_Succeeds(int initialRent, int attempt,
253253
[InlineData(true)]
254254
public void RentReturnRelease_SubsequentRentReturnsDifferentHandles(bool multiple)
255255
{
256-
var pool = new UniformUnmanagedMemoryPool(16, 16);
257-
using var cleanup = new CleanupUtil(pool);
258-
UnmanagedMemoryHandle b0 = pool.Rent();
259-
IntPtr h0 = b0.Handle;
260-
UnmanagedMemoryHandle b1 = pool.Rent();
261-
IntPtr h1 = b1.Handle;
262-
pool.Return(b0);
263-
pool.Return(b1);
264-
pool.Release();
256+
RemoteExecutor.Invoke(RunTest, multiple.ToString()).Dispose();
265257

266-
// Do some unmanaged allocations to make sure new pool buffers are different:
267-
IntPtr[] dummy = Enumerable.Range(0, 100).Select(_ => Marshal.AllocHGlobal(16)).ToArray();
268-
cleanup.Register(dummy);
269-
270-
if (multiple)
271-
{
272-
UnmanagedMemoryHandle b = pool.Rent();
273-
cleanup.Register(b);
274-
Assert.NotEqual(h0, b.Handle);
275-
Assert.NotEqual(h1, b.Handle);
276-
}
277-
else
258+
static void RunTest(string multipleInner)
278259
{
279-
UnmanagedMemoryHandle[] b = pool.Rent(2);
280-
cleanup.Register(b);
281-
Assert.NotEqual(h0, b[0].Handle);
282-
Assert.NotEqual(h1, b[0].Handle);
283-
Assert.NotEqual(h0, b[1].Handle);
284-
Assert.NotEqual(h1, b[1].Handle);
260+
var pool = new UniformUnmanagedMemoryPool(16, 16);
261+
using var cleanup = new CleanupUtil(pool);
262+
UnmanagedMemoryHandle b0 = pool.Rent();
263+
IntPtr h0 = b0.Handle;
264+
UnmanagedMemoryHandle b1 = pool.Rent();
265+
IntPtr h1 = b1.Handle;
266+
pool.Return(b0);
267+
pool.Return(b1);
268+
pool.Release();
269+
270+
// Do some unmanaged allocations to make sure new pool buffers are different:
271+
IntPtr[] dummy = Enumerable.Range(0, 100).Select(_ => Marshal.AllocHGlobal(16)).ToArray();
272+
cleanup.Register(dummy);
273+
274+
if (bool.Parse(multipleInner))
275+
{
276+
UnmanagedMemoryHandle b = pool.Rent();
277+
cleanup.Register(b);
278+
Assert.NotEqual(h0, b.Handle);
279+
Assert.NotEqual(h1, b.Handle);
280+
}
281+
else
282+
{
283+
UnmanagedMemoryHandle[] b = pool.Rent(2);
284+
cleanup.Register(b);
285+
Assert.NotEqual(h0, b[0].Handle);
286+
Assert.NotEqual(h1, b[0].Handle);
287+
Assert.NotEqual(h0, b[1].Handle);
288+
Assert.NotEqual(h1, b[1].Handle);
289+
}
285290
}
286291
}
287292

0 commit comments

Comments
 (0)