From c63a88032dbb558b1ff21120a35f353e7a9b4813 Mon Sep 17 00:00:00 2001 From: Christian Mazakas Date: Mon, 22 May 2023 12:10:10 -0700 Subject: [PATCH] Loosen restrictions on erase exceptions tests to accomodate runs where there are no successful erasures --- test/cfoa/exception_erase_tests.cpp | 82 +++++++++++------------------ 1 file changed, 30 insertions(+), 52 deletions(-) diff --git a/test/cfoa/exception_erase_tests.cpp b/test/cfoa/exception_erase_tests.cpp index 883ef710..bd3d8228 100644 --- a/test/cfoa/exception_erase_tests.cpp +++ b/test/cfoa/exception_erase_tests.cpp @@ -118,8 +118,6 @@ namespace { { using value_type = typename X::value_type; - std::atomic num_erased{0}; - auto const old_size = x.size(); auto const old_dc = +raii::default_constructor; @@ -145,29 +143,24 @@ namespace { }); enable_exceptions(); - thread_runner( - values, [&num_erased, &x, threshold](boost::span /* s */) { - for (std::size_t i = 0; i < 256; ++i) { - try { - auto count = x.erase_if([threshold](value_type& v) { - static std::atomic c{0}; - auto t = ++c; - if (should_throw && (t % throw_threshold == 0)) { - throw exception_tag{}; - } + thread_runner(values, [&x, threshold](boost::span /* s */) { + for (std::size_t i = 0; i < 256; ++i) { + try { + x.erase_if([threshold](value_type& v) { + static std::atomic c{0}; + auto t = ++c; + if (should_throw && (t % throw_threshold == 0)) { + throw exception_tag{}; + } - return v.second.x_ > threshold; - }); - - num_erased += count; - } catch (...) { - } + return v.second.x_ > threshold; + }); + } catch (...) { } - }); + } + }); disable_exceptions(); - BOOST_TEST_GT(num_erased, 0u); - BOOST_TEST_EQ(raii::default_constructor, old_dc); BOOST_TEST_EQ(raii::copy_constructor, old_cc); BOOST_TEST_EQ(raii::move_constructor, old_mc); @@ -182,8 +175,6 @@ namespace { { using value_type = typename X::value_type; - std::atomic num_erased{0}; - auto const old_size = x.size(); auto const old_dc = +raii::default_constructor; @@ -201,39 +192,26 @@ namespace { auto threshold = max / 2; - auto expected_erasures = 0u; - x.visit_all([&expected_erasures, threshold](value_type const& v) { - if (v.second.x_ > threshold) { - ++expected_erasures; + enable_exceptions(); + thread_runner(values, [&x, threshold](boost::span /* s */) { + for (std::size_t i = 0; i < 256; ++i) { + try { + boost::unordered::erase_if(x, [threshold](value_type& v) { + static std::atomic c{0}; + auto t = ++c; + if (should_throw && (t % throw_threshold == 0)) { + throw exception_tag{}; + } + + return v.second.x_ > threshold; + }); + + } catch (...) { + } } }); - - enable_exceptions(); - thread_runner( - values, [&num_erased, &x, threshold](boost::span /* s */) { - for (std::size_t i = 0; i < 256; ++i) { - try { - auto count = - boost::unordered::erase_if(x, [threshold](value_type& v) { - static std::atomic c{0}; - auto t = ++c; - if (should_throw && (t % throw_threshold == 0)) { - throw exception_tag{}; - } - - return v.second.x_ > threshold; - }); - - num_erased += count; - } catch (...) { - } - } - }); disable_exceptions(); - BOOST_TEST_GT(num_erased, 0u); - BOOST_TEST_LE(num_erased, expected_erasures); - BOOST_TEST_EQ(raii::default_constructor, old_dc); BOOST_TEST_EQ(raii::copy_constructor, old_cc); BOOST_TEST_EQ(raii::move_constructor, old_mc);