Skip to content

Commit

Permalink
core/semaphore: Add unit test for semaphore_units<>::split()
Browse files Browse the repository at this point in the history
Signed-off-by: Duarte Nunes <[email protected]>
  • Loading branch information
duarten committed Oct 7, 2018
1 parent 310bd99 commit fddd9d6
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions tests/semaphore_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -230,3 +230,19 @@ SEASTAR_TEST_CASE(test_with_semaphore) {
});
});
}

SEASTAR_THREAD_TEST_CASE(test_semaphore_units_splitting) {
auto sm = semaphore(2);
auto units = get_units(sm, 2, 1min).get0();
{
BOOST_REQUIRE_EQUAL(sm.available_units(), 0);
auto split = units.split(1);
BOOST_REQUIRE_EQUAL(sm.available_units(), 0);
}
BOOST_REQUIRE_EQUAL(sm.available_units(), 1);
units.~semaphore_units();
units = get_units(sm, 2, 1min).get0();
BOOST_REQUIRE_EQUAL(sm.available_units(), 0);
BOOST_REQUIRE_THROW(units.split(10), std::invalid_argument);
BOOST_REQUIRE_EQUAL(sm.available_units(), 0);
}

0 comments on commit fddd9d6

Please sign in to comment.