Skip to content

Commit

Permalink
Improve test coverage for shared pools
Browse files Browse the repository at this point in the history
  • Loading branch information
sharwell committed Nov 8, 2019
1 parent 58a3ca4 commit 27b044d
Showing 1 changed file with 16 additions and 2 deletions.
Expand Up @@ -211,17 +211,31 @@ public void TestClearAndFreeLarge()
[Fact]
public void TestPooledObjectHandlesNullAllocation()
{
object Allocator(ObjectPool<object> pool)
object NullAllocator(ObjectPool<object> pool)
=> null;

object NonNullAllocator(ObjectPool<object> pool)
=> new object();

bool releaserCalled = false;
void Releaser(ObjectPool<object> pool, object obj)
{
releaserCalled = true;
}

using (var obj = new PooledObject<object>(SharedPools.Default<object>(), Allocator, Releaser))
using (var obj = new PooledObject<object>(SharedPools.Default<object>(), NullAllocator, Releaser))
{
Assert.Null(obj.Object);
}

Assert.False(releaserCalled);

using (var obj = new PooledObject<object>(SharedPools.Default<object>(), NonNullAllocator, Releaser))
{
Assert.NotNull(obj.Object);
}

Assert.True(releaserCalled);
}
}
}

0 comments on commit 27b044d

Please sign in to comment.