diff options
Diffstat (limited to 'tests/unit/libutil')
-rw-r--r-- | tests/unit/libutil/pool.cc | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/tests/unit/libutil/pool.cc b/tests/unit/libutil/pool.cc index 127e42dda..3ad4ed3aa 100644 --- a/tests/unit/libutil/pool.cc +++ b/tests/unit/libutil/pool.cc @@ -65,21 +65,6 @@ namespace nix { ASSERT_EQ(pool.capacity(), 0); } - TEST(Pool, flushBadDropsOutOfScopeResources) { - auto isGood = [](const ref<TestResource> & r) { return false; }; - auto createResource = []() { return make_ref<TestResource>(); }; - - Pool<TestResource> pool = Pool<TestResource>((size_t)1, createResource, isGood); - - { - auto _r = pool.get(); - ASSERT_EQ(pool.count(), 1); - } - - pool.flushBad(); - ASSERT_EQ(pool.count(), 0); - } - // Test that the resources we allocate are being reused when they are still good. TEST(Pool, reuseResource) { auto isGood = [](const ref<TestResource> & r) { return true; }; @@ -124,4 +109,19 @@ namespace nix { ASSERT_NE(h->num, counter); } } + + TEST(Pool, throwingOperationDropsResource) + { + auto createResource = []() { return make_ref<TestResource>(); }; + + Pool<TestResource> pool = Pool<TestResource>((size_t)1, createResource); + + ASSERT_THROW({ + auto _r = pool.get(); + ASSERT_EQ(pool.count(), 1); + throw 1; + }, int); + + ASSERT_EQ(pool.count(), 0); + } } |