From b657d25a0e01e2fe31013b28318e9ad04ece9f33 Mon Sep 17 00:00:00 2001 From: Sean Parent Date: Thu, 14 Mar 2024 23:49:55 -0700 Subject: [PATCH] Fixing timeout in unit tests. --- .../channel/merge_channel_example.cpp | 22 +- docs/libraries/for_each_argument_example.cpp | 14 +- test/channel_process_tests.cpp | 56 ++- test/channel_test_helper.hpp | 15 +- test/channel_tests.cpp | 67 +-- test/future_coroutine_tests.cpp | 4 +- test/future_tests.cpp | 29 +- test/future_then_tests.cpp | 4 +- test/future_when_all_range_tests.cpp | 405 +++++++++--------- test/serial_queue_test.cpp | 22 +- test/tuple_test.cpp | 18 +- 11 files changed, 336 insertions(+), 320 deletions(-) diff --git a/docs/libraries/concurrency/channel/merge_channel_example.cpp b/docs/libraries/concurrency/channel/merge_channel_example.cpp index d41efa478..209d2b17b 100644 --- a/docs/libraries/concurrency/channel/merge_channel_example.cpp +++ b/docs/libraries/concurrency/channel/merge_channel_example.cpp @@ -2,6 +2,7 @@ #include #include +#include #include #include @@ -16,17 +17,14 @@ int main() { tie(send2, receive2) = channel(default_executor); tie(send3, receive3) = channel(default_executor); - std::atomic_int all_done{ 0 }; + std::atomic_int all_done{0}; - auto merged = merge_channel(default_executor, - [](int x) { return x; }, - receive1, - receive2, - receive3) - | [&_all_done = all_done](int x) { - cout << x << '\n'; - ++_all_done; - }; + auto merged = merge_channel( + default_executor, [](int x) { return x; }, receive1, receive2, receive3) | + [&_all_done = all_done](int x) { + cout << x << '\n'; + ++_all_done; + }; receive1.set_ready(); receive2.set_ready(); @@ -41,7 +39,7 @@ int main() { // Waiting just for illustrational purpose while (all_done < 6) { - this_thread::sleep_for(std::chrono::milliseconds(1)); + invoke_waiting([] { this_thread::sleep_for(std::chrono::milliseconds(1)); }); } pre_exit(); @@ -58,4 +56,4 @@ int main() { 4 5 6 -*/ \ No newline at end of file +*/ diff --git a/docs/libraries/for_each_argument_example.cpp b/docs/libraries/for_each_argument_example.cpp index 4ff5dea2d..4dfca0bd6 100644 --- a/docs/libraries/for_each_argument_example.cpp +++ b/docs/libraries/for_each_argument_example.cpp @@ -2,8 +2,9 @@ #include #include -#include +#include #include +#include #include #include @@ -11,16 +12,17 @@ using namespace stlab; using namespace std; int main(int, char**) { - auto fi = []{ + auto fi = [] { static std::size_t count_s{0}; return make_ready_future(count_s++, immediate_executor); }; - auto f = when_all(default_executor, [](auto... args){ - for_each_argument([](auto x) { cout << x << "\n"; }, args...); - }, fi(), fi(), fi()); + auto f = when_all( + default_executor, + [](auto... args) { for_each_argument([](auto x) { cout << x << "\n"; }, args...); }, fi(), + fi(), fi()); - while (!f.get_try()) this_thread::sleep_for(chrono::milliseconds(1)); + await(f); pre_exit(); } diff --git a/test/channel_process_tests.cpp b/test/channel_process_tests.cpp index 7f5a6b5bd..ad5609e90 100644 --- a/test/channel_process_tests.cpp +++ b/test/channel_process_tests.cpp @@ -8,6 +8,7 @@ #include +#include #include #include #include @@ -17,6 +18,8 @@ #include "channel_test_helper.hpp" +using namespace stlab; + using channel_test_fixture_int_1 = channel_test_helper::channel_test_fixture; BOOST_FIXTURE_TEST_SUITE(int_channel_process_void_functor, channel_test_fixture_int_1) @@ -164,14 +167,16 @@ BOOST_AUTO_TEST_CASE(int_channel_split_process_one_step) { std::atomic_int index2{0}; std::vector results2(10, 0); - auto check1 = _receive[0] | channel_test_helper::sum<1>() | [& _index = index1, &_results = results1](int x) { - _results[x] = x; - ++_index; - }; - auto check2 = _receive[0] | channel_test_helper::sum<1>() | [& _index = index2, &_results = results2](int x) { - _results[x] = x; - ++_index; - }; + auto check1 = _receive[0] | channel_test_helper::sum<1>() | + [&_index = index1, &_results = results1](int x) { + _results[x] = x; + ++_index; + }; + auto check2 = _receive[0] | channel_test_helper::sum<1>() | + [&_index = index2, &_results = results2](int x) { + _results[x] = x; + ++_index; + }; _receive[0].set_ready(); for (auto i = 0; i < 10; ++i) @@ -193,14 +198,16 @@ BOOST_AUTO_TEST_CASE(int_channel_split_process_two_steps) { std::atomic_int index2{0}; std::vector results2(5); - auto check1 = _receive[0] | channel_test_helper::sum<2>() | [& _index = index1, &_results = results1](int x) { - _results[_index] = x; - ++_index; - }; - auto check2 = _receive[0] | channel_test_helper::sum<2>() | [& _index = index2, &_results = results2](int x) { - _results[_index] = x; - ++_index; - }; + auto check1 = _receive[0] | channel_test_helper::sum<2>() | + [&_index = index1, &_results = results1](int x) { + _results[_index] = x; + ++_index; + }; + auto check2 = _receive[0] | channel_test_helper::sum<2>() | + [&_index = index2, &_results = results2](int x) { + _results[_index] = x; + ++_index; + }; _receive[0].set_ready(); for (auto i = 0; i < 10; ++i) @@ -221,8 +228,10 @@ BOOST_AUTO_TEST_CASE(int_channel_split_process_many_steps) { std::atomic_int result1{0}; std::atomic_int result2{0}; - auto check1 = _receive[0] | channel_test_helper::sum<10>() | [& _result = result1](int x) { _result = x; }; - auto check2 = _receive[0] | channel_test_helper::sum<10>() | [& _result = result2](int x) { _result = x; }; + auto check1 = + _receive[0] | channel_test_helper::sum<10>() | [&_result = result1](int x) { _result = x; }; + auto check2 = + _receive[0] | channel_test_helper::sum<10>() | [&_result = result2](int x) { _result = x; }; _receive[0].set_ready(); for (auto i = 0; i < 10; ++i) @@ -261,7 +270,7 @@ BOOST_AUTO_TEST_CASE(int_channel_process_with_two_steps_timed) { channel_test_helper::manual_scheduler::run_next_task(); while (result == 0) { - std::this_thread::sleep_for(std::chrono::milliseconds(10)); + invoke_waiting([] { std::this_thread::sleep_for(std::chrono::milliseconds(10)); }); } BOOST_REQUIRE_EQUAL(42, result); @@ -282,13 +291,14 @@ BOOST_AUTO_TEST_CASE(int_channel_process_with_two_steps_timed_wo_timeout) { send(42); while (channel_test_helper::timed_sum::current_sum() != 42) { - std::this_thread::sleep_for(std::chrono::milliseconds(10)); + invoke_waiting([] { std::this_thread::sleep_for(std::chrono::milliseconds(10)); }); } send(43); while (result == 0) { - std::this_thread::sleep_for(std::chrono::milliseconds(10)); + invoke_waiting([] { + std::this_thread::sleep_for(std::chrono::milliseconds(10)); }); } BOOST_REQUIRE_EQUAL(85, result); @@ -330,7 +340,7 @@ BOOST_AUTO_TEST_CASE(int_channel_process_set_error_is_called_on_upstream_error) send(42); while (!check) { - std::this_thread::sleep_for(std::chrono::milliseconds(10)); + invoke_waiting([] { std::this_thread::sleep_for(std::chrono::milliseconds(10)); }); } BOOST_REQUIRE_EQUAL(true, check.load()); @@ -372,7 +382,7 @@ BOOST_AUTO_TEST_CASE(int_channel_process_close_is_called_on_upstream_error) { send(42); while (!check) { - std::this_thread::sleep_for(std::chrono::milliseconds(10)); + invoke_waiting([] { std::this_thread::sleep_for(std::chrono::milliseconds(10)); }); } BOOST_REQUIRE_EQUAL(true, check.load()); diff --git a/test/channel_test_helper.hpp b/test/channel_test_helper.hpp index b3c831747..b61744b30 100644 --- a/test/channel_test_helper.hpp +++ b/test/channel_test_helper.hpp @@ -11,6 +11,7 @@ #include +#include #include #include #include @@ -18,7 +19,6 @@ #include #include - using lock_t = std::unique_lock; namespace channel_test_helper { @@ -42,7 +42,8 @@ class manual_scheduler { static void wait_until_queue_size_of(std::size_t n) { while (stlab::scope(_mutex, [&] { return _tasks.size(); }) < n) { - std::this_thread::sleep_for(std::chrono::milliseconds(1)); + stlab::invoke_waiting( + [] { std::this_thread::sleep_for(std::chrono::milliseconds(1)); }); } } @@ -63,7 +64,8 @@ struct channel_test_fixture_base { template void wait_until_done(F&& f) const { while (!std::forward(f)()) { - std::this_thread::sleep_for(std::chrono::milliseconds(1)); + stlab::invoke_waiting( + [] { std::this_thread::sleep_for(std::chrono::milliseconds(1)); }); } } }; @@ -73,9 +75,7 @@ struct channel_test_fixture : channel_test_fixture_base { std::array, N> _send; std::array, N> _receive; - channel_test_fixture() { - test_reset(); - } + channel_test_fixture() { test_reset(); } void test_reset() { for (std::size_t i = 0; i < N; i++) @@ -120,7 +120,8 @@ class channel_combine_test_fixture { template void wait_until_done(F&& f) const { while (!std::forward(f)()) { - std::this_thread::sleep_for(std::chrono::microseconds(1)); + stlab::invoke_waiting( + [] { std::this_thread::sleep_for(std::chrono::microseconds(1)); }); } } }; diff --git a/test/channel_tests.cpp b/test/channel_tests.cpp index 423bc7e62..5d2478d7a 100755 --- a/test/channel_tests.cpp +++ b/test/channel_tests.cpp @@ -14,6 +14,7 @@ #include +#include #include #include #include @@ -22,6 +23,8 @@ #include "channel_test_helper.hpp" +using namespace stlab; + BOOST_AUTO_TEST_CASE(int_sender) { BOOST_TEST_MESSAGE("int sender"); @@ -229,9 +232,11 @@ BOOST_AUTO_TEST_CASE(int_concatenate_two_channels) { BOOST_AUTO_TEST_CASE(int_concatenate_channels_with_different_executor) { { - std::atomic_int result{ 0 }; + std::atomic_int result{0}; - auto done = _receive[0] | (stlab::executor{stlab::immediate_executor } & [](int x) { return x + 1; }) | [&result](int x) { result = x; }; + auto done = _receive[0] | + (stlab::executor{stlab::immediate_executor} & [](int x) { return x + 1; }) | + [&result](int x) { result = x; }; _receive[0].set_ready(); @@ -243,9 +248,11 @@ BOOST_AUTO_TEST_CASE(int_concatenate_channels_with_different_executor) { } test_reset(); { - std::atomic_int result{ 0 }; + std::atomic_int result{0}; - auto done = _receive[0] | ([](int x) { return x + 1; } & stlab::executor{stlab::immediate_executor }) | [&result](int x) { result = x; }; + auto done = _receive[0] | + ([](int x) { return x + 1; } & stlab::executor{stlab::immediate_executor}) | + [&result](int x) { result = x; }; _receive[0].set_ready(); @@ -343,8 +350,8 @@ BOOST_AUTO_TEST_CASE(int_channel_with_2_sized_buffer) { generator> myGenerator(valuesInFlight); echo myEcho; - auto r2 = std::move(receive) | ref(myGenerator) | - (stlab::buffer_size{2} & std::ref(myEcho)) | [&valuesInFlight](auto x) { + auto r2 = std::move(receive) | ref(myGenerator) | (stlab::buffer_size{2} & std::ref(myEcho)) | + [&valuesInFlight](auto x) { BOOST_REQUIRE_EQUAL(x, valuesInFlight.front()); valuesInFlight.pop(); std::cout << x << std::endl; @@ -442,8 +449,7 @@ BOOST_AUTO_TEST_CASE(int_channel_with_3_sized_buffer) { BOOST_AUTO_TEST_CASE(int_channel_with_split_different_sized_buffer) { // Here the bigger buffer size must not steer the upstream, but the // smaller size - std::vector> bufferSizes = { - {1, 2}, {1, 2}, {1, 3}, {3, 1}, {2, 1}}; + std::vector> bufferSizes = {{1, 2}, {1, 2}, {1, 3}, {3, 1}, {2, 1}}; for (const auto& bs : bufferSizes) { main_queue q; @@ -456,14 +462,14 @@ BOOST_AUTO_TEST_CASE(int_channel_with_split_different_sized_buffer) { auto receive = stlab::channel(q.executor()); - auto g = - std::move(receive) | generator, std::queue>(valuesInFlight1, valuesInFlight2); + auto g = std::move(receive) | + generator, std::queue>(valuesInFlight1, valuesInFlight2); - auto r1 = g | (stlab::buffer_size{ bs.first } &echo()) | [&valuesInFlight1](auto x) { + auto r1 = g | (stlab::buffer_size{bs.first} & echo()) | [&valuesInFlight1](auto x) { BOOST_REQUIRE_EQUAL(x, valuesInFlight1.front()); valuesInFlight1.pop(); }; - auto r2 = g | (stlab::buffer_size{ bs.second } &echo()) | [&valuesInFlight2](auto x) { + auto r2 = g | (stlab::buffer_size{bs.second} & echo()) | [&valuesInFlight2](auto x) { BOOST_REQUIRE_EQUAL(x, valuesInFlight2.front()); valuesInFlight2.pop(); }; @@ -512,19 +518,19 @@ BOOST_AUTO_TEST_CASE(int_channel_with_split_different_sized_buffer) { BOOST_AUTO_TEST_CASE(int_channel_one_value_different_buffer_sizes) { BOOST_TEST_MESSAGE("int channel one value different buffer sizes"); - for (auto bs : std::vector{ 0, 1, 2, 10 }) { - stlab::sender send; - stlab::receiver receive; - std::tie(send, receive) = stlab::channel(stlab::default_executor); - std::atomic_int result{0}; + for (auto bs : std::vector{0, 1, 2, 10}) { + stlab::sender send; + stlab::receiver receive; + std::tie(send, receive) = stlab::channel(stlab::default_executor); + std::atomic_int result{0}; - auto check = receive | (stlab::buffer_size{ bs } &[&](int x) { result += x; }); + auto check = receive | (stlab::buffer_size{bs} & [&](int x) { result += x; }); receive.set_ready(); send(1); while (result < 1) { - std::this_thread::sleep_for(std::chrono::microseconds(1)); + invoke_waiting([] { std::this_thread::sleep_for(std::chrono::microseconds(1)); }); } BOOST_REQUIRE_EQUAL(1, result); @@ -534,20 +540,20 @@ BOOST_AUTO_TEST_CASE(int_channel_one_value_different_buffer_sizes) { BOOST_AUTO_TEST_CASE(int_channel_two_values_different_buffer_sizes) { BOOST_TEST_MESSAGE("int channel two values different buffer sizes"); - for (auto bs : std::vector{ 0, 1, 2, 10 }) { + for (auto bs : std::vector{0, 1, 2, 10}) { stlab::sender send; stlab::receiver receive; std::tie(send, receive) = stlab::channel(stlab::default_executor); std::atomic_int result{0}; - auto check = receive | (stlab::buffer_size{ bs } &[&](int x) { result += x; }); + auto check = receive | (stlab::buffer_size{bs} & [&](int x) { result += x; }); receive.set_ready(); send(1); send(1); while (result < 2) { - std::this_thread::sleep_for(std::chrono::microseconds(1)); + invoke_waiting([] { std::this_thread::sleep_for(std::chrono::microseconds(1)); }); } BOOST_REQUIRE_EQUAL(2, result); @@ -558,45 +564,44 @@ BOOST_AUTO_TEST_CASE(int_channel_many_values_different_buffer_sizes) { BOOST_TEST_MESSAGE("int channel many values different buffer sizes"); { - for (auto bs : std::vector{ 0, 1, 2, 10 }) { + for (auto bs : std::vector{0, 1, 2, 10}) { stlab::sender send; stlab::receiver receive; std::tie(send, receive) = stlab::channel(stlab::default_executor); - std::atomic_int result{ 0 }; + std::atomic_int result{0}; - auto check = receive | (stlab::buffer_size{ bs } &[&](int x) { result += x; }); + auto check = receive | (stlab::buffer_size{bs} & [&](int x) { result += x; }); receive.set_ready(); for (auto i = 0; i < 10; ++i) send(1); while (result < 10) { - std::this_thread::sleep_for(std::chrono::microseconds(1)); + invoke_waiting([] { std::this_thread::sleep_for(std::chrono::microseconds(1)); }); } BOOST_REQUIRE_EQUAL(10, result); } } { - for (auto bs : std::vector{ 0, 1, 2, 10 }) { + for (auto bs : std::vector{0, 1, 2, 10}) { stlab::sender send; stlab::receiver receive; std::tie(send, receive) = stlab::channel(stlab::default_executor); - std::atomic_int result{ 0 }; + std::atomic_int result{0}; - auto check = receive | ([&](int x) { result += x; } & stlab::buffer_size{ bs }); + auto check = receive | ([&](int x) { result += x; } & stlab::buffer_size{bs}); receive.set_ready(); for (auto i = 0; i < 10; ++i) send(1); while (result < 10) { - std::this_thread::sleep_for(std::chrono::microseconds(1)); + invoke_waiting([] { std::this_thread::sleep_for(std::chrono::microseconds(1)); }); } BOOST_REQUIRE_EQUAL(10, result); } - } } diff --git a/test/future_coroutine_tests.cpp b/test/future_coroutine_tests.cpp index 2d65d347a..271b09767 100644 --- a/test/future_coroutine_tests.cpp +++ b/test/future_coroutine_tests.cpp @@ -54,7 +54,7 @@ BOOST_AUTO_TEST_CASE(future_coroutine_void) { stlab::future get_the_answer_with_failure() { auto result = co_await stlab::async(stlab::default_executor, [] { - std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + invoke_waiting([] { std::this_thread::sleep_for(std::chrono::milliseconds(1000)); }); return 42; }); throw test_exception("failure"); @@ -75,7 +75,7 @@ BOOST_AUTO_TEST_CASE(future_coroutine_int_failure) { stlab::future get_the_answer_move_only_with_failure() { auto result = co_await stlab::async(stlab::default_executor, [] { - std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + invoke_waiting([] { std::this_thread::sleep_for(std::chrono::milliseconds(1000)); }); return move_only{42}; }); throw test_exception("failure"); diff --git a/test/future_tests.cpp b/test/future_tests.cpp index 30dd39ca1..d02da3788 100644 --- a/test/future_tests.cpp +++ b/test/future_tests.cpp @@ -249,12 +249,9 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(future_constructed_minimal_fn_with_parameters, auto sut = async(make_executor<0>(), [](auto x) -> T { return x + T(0); }, T(42)); BOOST_REQUIRE(sut.valid() == true); - while (!sut.get_try()) { - std::this_thread::sleep_for(std::chrono::milliseconds(1)); - } + auto result = await(std::move(sut)); - BOOST_REQUIRE(!sut.exception()); - BOOST_WARN_EQUAL(T(42) + T(0), *sut.get_try()); + BOOST_WARN_EQUAL(T(42) + T(0), result); } BOOST_REQUIRE_EQUAL(1, custom_scheduler<0>::usage_counter()); } @@ -264,15 +261,13 @@ BOOST_AUTO_TEST_CASE(future_constructed_minimal_fn_moveonly) { test_setup setup; { - auto sut = async(make_executor<0>(), []() -> stlab::move_only { return stlab::move_only{42}; }); + auto sut = + async(make_executor<0>(), []() -> stlab::move_only { return stlab::move_only{42}; }); BOOST_REQUIRE(sut.valid() == true); - while (!sut.get_try()) { - std::this_thread::sleep_for(std::chrono::milliseconds(1)); - } + auto result = await(std::move(sut)); - BOOST_REQUIRE(!sut.exception()); - BOOST_REQUIRE_EQUAL(42, sut.get_try()->member()); + BOOST_REQUIRE_EQUAL(42, result.member()); } BOOST_REQUIRE_EQUAL(1, custom_scheduler<0>::usage_counter()); } @@ -436,7 +431,9 @@ BOOST_AUTO_TEST_CASE(future_wait_void_with_timeout) { BOOST_AUTO_TEST_CASE(future_wait_void_with_timeout_reached) { BOOST_TEST_MESSAGE("future wait with void with a timeout"); - auto answer = [&] { std::this_thread::sleep_for(std::chrono::milliseconds(500)); }; + auto answer = [&] { + invoke_waiting([] { std::this_thread::sleep_for(std::chrono::milliseconds(500)); }); + }; stlab::future f = stlab::async(stlab::default_executor, answer); f = stlab::await_for(std::move(f), std::chrono::milliseconds(100)); @@ -447,7 +444,7 @@ BOOST_AUTO_TEST_CASE(future_wait_void_with_timeout_reached) { BOOST_AUTO_TEST_CASE(future_wait_int_with_timeout_reached) { BOOST_TEST_MESSAGE("future wait with int with a timeout"); auto answer = [&] { - std::this_thread::sleep_for(std::chrono::milliseconds(500)); + stlab::invoke_waiting([] { std::this_thread::sleep_for(std::chrono::milliseconds(500)); }); return 42; }; @@ -460,7 +457,7 @@ BOOST_AUTO_TEST_CASE(future_wait_int_with_timeout_reached) { BOOST_AUTO_TEST_CASE(future_wait_move_only_with_timeout_reached) { BOOST_TEST_MESSAGE("future wait with move_only with a timeout"); auto answer = [&] { - std::this_thread::sleep_for(std::chrono::milliseconds(500)); + stlab::invoke_waiting([] { std::this_thread::sleep_for(std::chrono::milliseconds(500)); }); return move_only(42); }; @@ -519,7 +516,7 @@ BOOST_AUTO_TEST_CASE(future_wait_void_error_case_with_timeout) { BOOST_AUTO_TEST_CASE(future_wait_copyable_value_timeout) { BOOST_TEST_MESSAGE("future wait with copyable value with timeout"); auto answer = [] { - std::this_thread::sleep_for(std::chrono::seconds(1)); + stlab::invoke_waiting([] { std::this_thread::sleep_for(std::chrono::seconds(1)); }); return 42; }; @@ -533,7 +530,7 @@ BOOST_AUTO_TEST_CASE(future_wait_copyable_value_timeout) { BOOST_AUTO_TEST_CASE(future_wait_moveonly_value_and_timeout) { BOOST_TEST_MESSAGE("future wait with moveonly value"); auto answer = [] { - std::this_thread::sleep_for(std::chrono::milliseconds(1)); + stlab::invoke_waiting([] { std::this_thread::sleep_for(std::chrono::milliseconds(1)); }); return stlab::move_only(42); }; diff --git a/test/future_then_tests.cpp b/test/future_then_tests.cpp index 88df30b7b..6fafdcc34 100755 --- a/test/future_then_tests.cpp +++ b/test/future_then_tests.cpp @@ -404,7 +404,7 @@ BOOST_AUTO_TEST_CASE(future_then_non_copyable_detach) { }).detach(); } while (!check) { - this_thread::sleep_for(chrono::milliseconds(1)); + invoke_waiting([] { this_thread::sleep_for(chrono::milliseconds(1)); }); } } @@ -858,7 +858,7 @@ BOOST_AUTO_TEST_CASE(future_int_single_task_detached) { detached.detach(); } while (!check) { - this_thread::sleep_for(chrono::milliseconds(1)); + invoke_waiting([] { this_thread::sleep_for(chrono::milliseconds(1)); }); } } diff --git a/test/future_when_all_range_tests.cpp b/test/future_when_all_range_tests.cpp index 647db8776..58c43c1ee 100644 --- a/test/future_when_all_range_tests.cpp +++ b/test/future_when_all_range_tests.cpp @@ -6,9 +6,10 @@ /**************************************************************************************************/ -#include #include +#include +#include #include #include #include @@ -26,8 +27,9 @@ BOOST_AUTO_TEST_CASE(future_when_all_void_void_empty_range) { bool check = {false}; std::vector> emptyFutures; - sut = when_all(make_executor<0>(), [& _check = check]() { _check = true; }, - std::make_pair(emptyFutures.begin(), emptyFutures.end())); + sut = when_all( + make_executor<0>(), [&_check = check]() { _check = true; }, + std::make_pair(emptyFutures.begin(), emptyFutures.end())); check_valid_future(sut); wait_until_future_completed(sut); @@ -41,8 +43,9 @@ BOOST_AUTO_TEST_CASE(future_when_all_void_empty_range) { size_t p = 0; std::vector> emptyFutures; - sut = when_all(make_executor<0>(), [& _p = p](std::vector v) { _p = v.size(); }, - std::make_pair(emptyFutures.begin(), emptyFutures.end())); + sut = when_all( + make_executor<0>(), [&_p = p](std::vector v) { _p = v.size(); }, + std::make_pair(emptyFutures.begin(), emptyFutures.end())); check_valid_future(sut); wait_until_future_completed(sut); @@ -58,12 +61,13 @@ BOOST_AUTO_TEST_CASE(future_when_all_void_range_with_one_element) { std::vector> futures; futures.push_back(async(make_executor<0>(), [] { return 42; })); - sut = when_all(make_executor<1>(), - [& _p = p, &_r = r](std::vector v) { - _p = v.size(); - _r = v[0]; - }, - std::make_pair(futures.begin(), futures.end())); + sut = when_all( + make_executor<1>(), + [&_p = p, &_r = r](std::vector v) { + _p = v.size(); + _r = v[0]; + }, + std::make_pair(futures.begin(), futures.end())); check_valid_future(sut); wait_until_future_completed(sut); @@ -77,27 +81,25 @@ BOOST_AUTO_TEST_CASE(future_when_all_void_range_with_one_element) { BOOST_AUTO_TEST_CASE(future_when_all_void_range_with_all_delayed) { using namespace std::chrono_literals; - stlab::serial_queue_t seriel_queue_1 {stlab::default_executor}; - stlab::serial_queue_t seriel_queue_2 {stlab::default_executor}; - stlab::serial_queue_t seriel_queue_3 {stlab::default_executor}; + stlab::serial_queue_t seriel_queue_1{stlab::default_executor}; + stlab::serial_queue_t seriel_queue_2{stlab::default_executor}; + stlab::serial_queue_t seriel_queue_3{stlab::default_executor}; std::vector> test_futures; - test_futures.emplace_back( - stlab::async(seriel_queue_1.executor(), []{ - std::this_thread::sleep_for(0.1s);}) - ); - - test_futures.emplace_back( - stlab::async(seriel_queue_2.executor(), []{ - std::this_thread::sleep_for(0.1s);}) - ); - - test_futures.emplace_back( - stlab::async(seriel_queue_3.executor(), []{ - std::this_thread::sleep_for(0.1s);}) - ); + test_futures.emplace_back(stlab::async(seriel_queue_1.executor(), [] { + invoke_waiting([] { std::this_thread::sleep_for(0.1s); }); + })); + + test_futures.emplace_back(stlab::async(seriel_queue_2.executor(), [] { + invoke_waiting([] { std::this_thread::sleep_for(0.1s); }); + })); + + test_futures.emplace_back(stlab::async(seriel_queue_3.executor(), [] { + invoke_waiting([] { std::this_thread::sleep_for(0.1s); }); + })); bool done{false}; - auto done_future = stlab::when_all(stlab::default_executor, [&done] { done = true;}, + auto done_future = stlab::when_all( + stlab::default_executor, [&done] { done = true; }, std::make_pair(test_futures.begin(), test_futures.end())); stlab::await(done_future); @@ -115,14 +117,15 @@ BOOST_AUTO_TEST_CASE(future_when_all_void_range_with_many_elements) { futures.push_back(async(make_executor<0>(), [] { return 3; })); futures.push_back(async(make_executor<0>(), [] { return 5; })); - sut = when_all(make_executor<1>(), - [& _p = p, &_r = r](std::vector v) { - _p = v.size(); - for (auto i : v) { - _r += i; - } - }, - std::make_pair(futures.begin(), futures.end())); + sut = when_all( + make_executor<1>(), + [&_p = p, &_r = r](std::vector v) { + _p = v.size(); + for (auto i : v) { + _r += i; + } + }, + std::make_pair(futures.begin(), futures.end())); check_valid_future(sut); wait_until_future_completed(sut); @@ -134,7 +137,8 @@ BOOST_AUTO_TEST_CASE(future_when_all_void_range_with_many_elements) { } BOOST_AUTO_TEST_CASE(future_when_all_void_range_with_many_elements_and_immediate_continuation) { - BOOST_TEST_MESSAGE("running future when_all void with range with many elements and immediate continuation"); + BOOST_TEST_MESSAGE( + "running future when_all void with range with many elements and immediate continuation"); size_t p = 0; size_t r = 0; std::vector> futures; @@ -142,14 +146,15 @@ BOOST_AUTO_TEST_CASE(future_when_all_void_range_with_many_elements_and_immediate futures.push_back(async(make_executor<0>(), [] { return 1; })); } - sut = when_all(immediate_executor, - [& _p = p, &_r = r](std::vector v) { - _p = v.size(); - for (auto i : v) { - _r += i; - } - }, - std::make_pair(futures.begin(), futures.end())); + sut = when_all( + immediate_executor, + [&_p = p, &_r = r](std::vector v) { + _p = v.size(); + for (auto i : v) { + _r += i; + } + }, + std::make_pair(futures.begin(), futures.end())); check_valid_future(sut); wait_until_future_completed(sut); @@ -172,18 +177,19 @@ BOOST_AUTO_TEST_CASE(future_when_all_void_range_with_diamond_formation_elements) int r = 0; auto start = async(make_executor<0>(), [] { return 4711; }); std::vector> futures(4); - futures[0] = start.then(make_executor<0>(), [& _p = v[0]](auto x) { _p = x + 1; }); - futures[1] = start.then(make_executor<0>(), [& _p = v[1]](auto x) { _p = x + 2; }); - futures[2] = start.then(make_executor<0>(), [& _p = v[2]](auto x) { _p = x + 3; }); - futures[3] = start.then(make_executor<0>(), [& _p = v[3]](auto x) { _p = x + 5; }); - - sut = when_all(make_executor<1>(), - [& _r = r, &v]() { - for (auto i : v) { - _r += i; - } - }, - std::make_pair(futures.begin(), futures.end())); + futures[0] = start.then(make_executor<0>(), [&_p = v[0]](auto x) { _p = x + 1; }); + futures[1] = start.then(make_executor<0>(), [&_p = v[1]](auto x) { _p = x + 2; }); + futures[2] = start.then(make_executor<0>(), [&_p = v[2]](auto x) { _p = x + 3; }); + futures[3] = start.then(make_executor<0>(), [&_p = v[3]](auto x) { _p = x + 5; }); + + sut = when_all( + make_executor<1>(), + [&_r = r, &v]() { + for (auto i : v) { + _r += i; + } + }, + std::make_pair(futures.begin(), futures.end())); check_valid_future(sut); wait_until_future_completed(sut); @@ -194,16 +200,15 @@ BOOST_AUTO_TEST_CASE(future_when_all_void_range_with_diamond_formation_elements) } BOOST_AUTO_TEST_SUITE_END() - BOOST_FIXTURE_TEST_SUITE(future_when_all_range_int, test_fixture) BOOST_AUTO_TEST_CASE(future_when_all_int_empty_range) { BOOST_TEST_MESSAGE("running future when_all int with empty range"); std::vector> emptyFutures; - sut = when_all(make_executor<0>(), - [](std::vector v) { return static_cast(v.size()); }, - std::make_pair(emptyFutures.begin(), emptyFutures.end())); + sut = when_all( + make_executor<0>(), [](std::vector v) { return static_cast(v.size()); }, + std::make_pair(emptyFutures.begin(), emptyFutures.end())); check_valid_future(sut); wait_until_future_completed(sut); @@ -217,12 +222,13 @@ BOOST_AUTO_TEST_CASE(future_when_all_int_range_with_one_element) { std::vector> futures; futures.push_back(async(make_executor<0>(), [] { return 42; })); - sut = when_all(make_executor<1>(), - [& _p = p](std::vector v) { - _p = v.size(); - return v[0]; - }, - std::make_pair(futures.begin(), futures.end())); + sut = when_all( + make_executor<1>(), + [&_p = p](std::vector v) { + _p = v.size(); + return v[0]; + }, + std::make_pair(futures.begin(), futures.end())); check_valid_future(sut); wait_until_future_completed(sut); @@ -242,16 +248,17 @@ BOOST_AUTO_TEST_CASE(future_when_all_int_range_with_many_elements) { futures.push_back(async(make_executor<0>(), [] { return 3; })); futures.push_back(async(make_executor<0>(), [] { return 5; })); - sut = when_all(make_executor<1>(), - [& _p = p](std::vector v) { - _p = v.size(); - auto r = 0; - for (auto i : v) { - r += i; - } - return r; - }, - std::make_pair(futures.begin(), futures.end())); + sut = when_all( + make_executor<1>(), + [&_p = p](std::vector v) { + _p = v.size(); + auto r = 0; + for (auto i : v) { + r += i; + } + return r; + }, + std::make_pair(futures.begin(), futures.end())); check_valid_future(sut); wait_until_future_completed(sut); @@ -279,16 +286,17 @@ BOOST_AUTO_TEST_CASE(future_when_all_int_range_with_diamond_formation_elements) futures[2] = start.then(make_executor<0>(), [](auto x) { return x + 3; }); futures[3] = start.then(make_executor<0>(), [](auto x) { return x + 5; }); - sut = when_all(make_executor<1>(), - [& _p = p](std::vector v) { - _p = v.size(); - auto r = 0; - for (auto i : v) { - r += i; - } - return r; - }, - std::make_pair(futures.begin(), futures.end())); + sut = when_all( + make_executor<1>(), + [&_p = p](std::vector v) { + _p = v.size(); + auto r = 0; + for (auto i : v) { + r += i; + } + return r; + }, + std::make_pair(futures.begin(), futures.end())); check_valid_future(sut); wait_until_future_completed(sut); @@ -301,8 +309,6 @@ BOOST_AUTO_TEST_CASE(future_when_all_int_range_with_diamond_formation_elements) BOOST_AUTO_TEST_SUITE_END() - - BOOST_FIXTURE_TEST_SUITE(future_when_all_range_move_only, test_fixture) BOOST_AUTO_TEST_CASE(future_when_all_move_range_with_many_elements) { @@ -314,33 +320,32 @@ BOOST_AUTO_TEST_CASE(future_when_all_move_range_with_many_elements) { futures.push_back(async(make_executor<0>(), [] { return stlab::move_only{3}; })); futures.push_back(async(make_executor<0>(), [] { return stlab::move_only{5}; })); - sut = when_all(make_executor<1>(), - [& _p = p](std::vector v) { - _p = v.size(); - auto r = 0; - for (const auto& i : v) { - r += i.member(); - } - return stlab::move_only{r}; - }, - std::make_pair(futures.begin(), futures.end())); + sut = when_all( + make_executor<1>(), + [&_p = p](std::vector v) { + _p = v.size(); + auto r = 0; + for (const auto& i : v) { + r += i.member(); + } + return stlab::move_only{r}; + }, + std::make_pair(futures.begin(), futures.end())); check_valid_future(sut); auto result = await(std::move(sut)); BOOST_REQUIRE_EQUAL(size_t(4), p); - BOOST_REQUIRE_EQUAL(1 + 2 + 3 + 5, result.member() ); + BOOST_REQUIRE_EQUAL(1 + 2 + 3 + 5, result.member()); BOOST_REQUIRE_LE(4, custom_scheduler<0>::usage_counter()); BOOST_REQUIRE_LE(1, custom_scheduler<1>::usage_counter()); } BOOST_AUTO_TEST_SUITE_END() - BOOST_AUTO_TEST_CASE(future_when_all_range_with_mutable_task) { BOOST_TEST_MESSAGE("future when all range with mutable task"); - struct mutable_int - { + struct mutable_int { int i = 0; auto operator()() { ++i; @@ -348,32 +353,33 @@ BOOST_AUTO_TEST_CASE(future_when_all_range_with_mutable_task) { } }; mutable_int func1, func2; - std::vector> futures { - async(stlab::default_executor, [func = std::move(func1)]() mutable { - func(); - return std::move(func); - }), + std::vector> futures{ + async(stlab::default_executor, + [func = std::move(func1)]() mutable { + func(); + return std::move(func); + }), async(stlab::default_executor, [func = std::move(func2)]() mutable { func(); return std::move(func); - }) - }; - auto sut = when_all(stlab::default_executor, [](auto result) { - return std::accumulate(result.begin(), result.end(), 0, [](int sum, auto f){ return sum + f(); }); + })}; + auto sut = when_all( + stlab::default_executor, + [](auto result) { + return std::accumulate(result.begin(), result.end(), 0, + [](int sum, auto f) { return sum + f(); }); }, - std::make_pair(futures.begin(), futures.end()) - ); + std::make_pair(futures.begin(), futures.end())); BOOST_REQUIRE_EQUAL(4, stlab::await(sut)); } - BOOST_AUTO_TEST_CASE(future_when_all_range_with_mutable_void_task) { BOOST_TEST_MESSAGE("future when all range with mutable void task"); std::atomic_int check{0}; struct mutable_int { - std::atomic_int& _check; + std::atomic_int& _check; int i = 0; void operator()() { ++i; @@ -381,23 +387,20 @@ BOOST_AUTO_TEST_CASE(future_when_all_range_with_mutable_void_task) { } }; - mutable_int func1{ check }, func2{check}; + mutable_int func1{check}, func2{check}; std::vector> futures{ async(stlab::default_executor, [func = func1]() mutable { func(); }), async(stlab::default_executor, [func = func2]() mutable { func(); })}; - future sut = when_all(stlab::default_executor, - [_func = mutable_int{check}]() mutable { - _func(); - }, - std::make_pair(futures.begin(), futures.end())); + future sut = when_all( + stlab::default_executor, [_func = mutable_int{check}]() mutable { _func(); }, + std::make_pair(futures.begin(), futures.end())); stlab::await(sut); BOOST_REQUIRE_EQUAL(3, check); } - // ---------------------------------------------------------------------------- // Error cases // ---------------------------------------------------------------------------- @@ -408,15 +411,15 @@ BOOST_AUTO_TEST_CASE(future_when_all_void_range_with_one_element) { size_t p = 0; size_t r = 0; std::vector> futures; - futures.push_back( - async(make_executor<0>(), []() -> int { throw test_exception("failure"); })); + futures.push_back(async(make_executor<0>(), []() -> int { throw test_exception("failure"); })); - sut = when_all(make_executor<1>(), - [& _p = p, &_r = r](const std::vector& v) { - _p = v.size(); - _r = v[0]; - }, - std::make_pair(futures.begin(), futures.end())); + sut = when_all( + make_executor<1>(), + [&_p = p, &_r = r](const std::vector& v) { + _p = v.size(); + _r = v[0]; + }, + std::make_pair(futures.begin(), futures.end())); wait_until_future_fails(sut); @@ -433,20 +436,20 @@ BOOST_AUTO_TEST_CASE(future_when_all_void_range_with_many_elements_one_failing) size_t p = 0; size_t r = 0; std::vector> futures; - futures.push_back( - async(make_executor<0>(), []() -> int { throw test_exception("failure"); })); + futures.push_back(async(make_executor<0>(), []() -> int { throw test_exception("failure"); })); futures.push_back(async(make_executor<0>(), [] { return 2; })); futures.push_back(async(make_executor<0>(), [] { return 3; })); futures.push_back(async(make_executor<0>(), [] { return 5; })); - sut = when_all(make_executor<1>(), - [& _p = p, &_r = r](const std::vector& v) { - _p = v.size(); - for (auto i : v) { - _r += i; - } - }, - std::make_pair(futures.begin(), futures.end())); + sut = when_all( + make_executor<1>(), + [&_p = p, &_r = r](const std::vector& v) { + _p = v.size(); + for (auto i : v) { + _r += i; + } + }, + std::make_pair(futures.begin(), futures.end())); wait_until_future_fails(sut); @@ -463,23 +466,20 @@ BOOST_AUTO_TEST_CASE(future_when_all_void_range_with_many_elements_all_failing) size_t p = 0; size_t r = 0; std::vector> futures; - futures.push_back( - async(make_executor<0>(), []() -> int { throw test_exception("failure"); })); - futures.push_back( - async(make_executor<0>(), []() -> int { throw test_exception("failure"); })); - futures.push_back( - async(make_executor<0>(), []() -> int { throw test_exception("failure"); })); - futures.push_back( - async(make_executor<0>(), []() -> int { throw test_exception("failure"); })); - - sut = when_all(make_executor<1>(), - [& _p = p, &_r = r](const std::vector& v) { - _p = v.size(); - for (auto i : v) { - _r += i; - } - }, - std::make_pair(futures.begin(), futures.end())); + futures.push_back(async(make_executor<0>(), []() -> int { throw test_exception("failure"); })); + futures.push_back(async(make_executor<0>(), []() -> int { throw test_exception("failure"); })); + futures.push_back(async(make_executor<0>(), []() -> int { throw test_exception("failure"); })); + futures.push_back(async(make_executor<0>(), []() -> int { throw test_exception("failure"); })); + + sut = when_all( + make_executor<1>(), + [&_p = p, &_r = r](const std::vector& v) { + _p = v.size(); + for (auto i : v) { + _r += i; + } + }, + std::make_pair(futures.begin(), futures.end())); wait_until_future_fails(sut); @@ -504,18 +504,19 @@ BOOST_AUTO_TEST_CASE(future_when_all_void_range_with_diamond_formation_elements_ int r = 0; auto start = async(make_executor<0>(), []() -> int { throw test_exception("failure"); }); std::vector> futures(4); - futures[0] = start.then(make_executor<0>(), [& _p = v[0]](auto x) { _p = x + 1; }); - futures[1] = start.then(make_executor<0>(), [& _p = v[1]](auto x) { _p = x + 2; }); - futures[2] = start.then(make_executor<0>(), [& _p = v[2]](auto x) { _p = x + 3; }); - futures[3] = start.then(make_executor<0>(), [& _p = v[3]](auto x) { _p = x + 5; }); - - sut = when_all(make_executor<1>(), - [& _r = r, &v]() { - for (auto i : v) { - _r += i; - } - }, - std::make_pair(futures.begin(), futures.end())); + futures[0] = start.then(make_executor<0>(), [&_p = v[0]](auto x) { _p = x + 1; }); + futures[1] = start.then(make_executor<0>(), [&_p = v[1]](auto x) { _p = x + 2; }); + futures[2] = start.then(make_executor<0>(), [&_p = v[2]](auto x) { _p = x + 3; }); + futures[3] = start.then(make_executor<0>(), [&_p = v[3]](auto x) { _p = x + 5; }); + + sut = when_all( + make_executor<1>(), + [&_r = r, &v]() { + for (auto i : v) { + _r += i; + } + }, + std::make_pair(futures.begin(), futures.end())); wait_until_future_fails(sut); @@ -536,18 +537,19 @@ BOOST_AUTO_TEST_CASE( int r = 0; auto start = async(make_executor<0>(), []() -> int { return 42; }); std::vector> futures(4); - futures[0] = start.then(make_executor<0>(), [& _p = v[0]](auto x) { _p = x + 1; }); + futures[0] = start.then(make_executor<0>(), [&_p = v[0]](auto x) { _p = x + 1; }); futures[1] = start.then(make_executor<0>(), [](auto) { throw test_exception("failure"); }); - futures[2] = start.then(make_executor<0>(), [& _p = v[2]](auto x) { _p = x + 3; }); - futures[3] = start.then(make_executor<0>(), [& _p = v[3]](auto x) { _p = x + 5; }); - - sut = when_all(make_executor<1>(), - [& _r = r, &v]() { - for (auto i : v) { - _r += i; - } - }, - std::make_pair(futures.begin(), futures.end())); + futures[2] = start.then(make_executor<0>(), [&_p = v[2]](auto x) { _p = x + 3; }); + futures[3] = start.then(make_executor<0>(), [&_p = v[3]](auto x) { _p = x + 5; }); + + sut = when_all( + make_executor<1>(), + [&_r = r, &v]() { + for (auto i : v) { + _r += i; + } + }, + std::make_pair(futures.begin(), futures.end())); wait_until_future_fails(sut); @@ -564,13 +566,14 @@ BOOST_AUTO_TEST_CASE(future_when_all_void_range_with_diamond_formation_elements_ int r = 0; auto start = async(make_executor<0>(), []() -> int { return 42; }); std::vector> futures(4); - futures[0] = start.then(make_executor<0>(), [& _p = v[0]](auto x) { _p = x + 1; }); - futures[1] = start.then(make_executor<0>(), [& _p = v[1]](auto x) { _p = x + 2; }); - futures[2] = start.then(make_executor<0>(), [& _p = v[2]](auto x) { _p = x + 3; }); - futures[3] = start.then(make_executor<0>(), [& _p = v[3]](auto x) { _p = x + 5; }); + futures[0] = start.then(make_executor<0>(), [&_p = v[0]](auto x) { _p = x + 1; }); + futures[1] = start.then(make_executor<0>(), [&_p = v[1]](auto x) { _p = x + 2; }); + futures[2] = start.then(make_executor<0>(), [&_p = v[2]](auto x) { _p = x + 3; }); + futures[3] = start.then(make_executor<0>(), [&_p = v[3]](auto x) { _p = x + 5; }); - sut = when_all(make_executor<1>(), []() { throw test_exception("failure"); }, - std::make_pair(futures.begin(), futures.end())); + sut = when_all( + make_executor<1>(), []() { throw test_exception("failure"); }, + std::make_pair(futures.begin(), futures.end())); wait_until_future_fails(sut); @@ -580,28 +583,31 @@ BOOST_AUTO_TEST_CASE(future_when_all_void_range_with_diamond_formation_elements_ BOOST_REQUIRE_LE(1, custom_scheduler<1>::usage_counter()); } -BOOST_AUTO_TEST_CASE(future_when_all_void_range_with_one_fails_ofmany_elements_and_immediate_continuation) { - BOOST_TEST_MESSAGE("running future when_all void with range with one fails one of manyelements and immediate continuation"); +BOOST_AUTO_TEST_CASE( + future_when_all_void_range_with_one_fails_ofmany_elements_and_immediate_continuation) { + BOOST_TEST_MESSAGE( + "running future when_all void with range with one fails one of manyelements and immediate continuation"); size_t p = 0; size_t r = 0; std::vector> futures; for (auto i = 0; i < 500; ++i) { futures.push_back(async(make_executor<0>(), [] { return 1; })); } - futures.push_back(async(make_executor<0>(), []()->int { throw test_exception("failure"); })); + futures.push_back(async(make_executor<0>(), []() -> int { throw test_exception("failure"); })); for (auto i = 0; i < 499; ++i) { futures.push_back(async(make_executor<0>(), [] { return 1; })); } - sut = when_all(immediate_executor, - [& _p = p, &_r = r](std::vector v) { - _p = v.size(); - for (auto i : v) { - _r += i; - } - }, - std::make_pair(futures.begin(), futures.end())); + sut = when_all( + immediate_executor, + [&_p = p, &_r = r](std::vector v) { + _p = v.size(); + for (auto i : v) { + _r += i; + } + }, + std::make_pair(futures.begin(), futures.end())); wait_until_future_fails(sut); @@ -609,5 +615,4 @@ BOOST_AUTO_TEST_CASE(future_when_all_void_range_with_one_fails_ofmany_elements_a BOOST_REQUIRE_EQUAL(0, r); } - BOOST_AUTO_TEST_SUITE_END() diff --git a/test/serial_queue_test.cpp b/test/serial_queue_test.cpp index eec469cf5..11827b9a0 100644 --- a/test/serial_queue_test.cpp +++ b/test/serial_queue_test.cpp @@ -2,6 +2,7 @@ #include #include +#include #include #include #include @@ -14,7 +15,9 @@ using namespace stlab; /**************************************************************************************************/ -inline void rest() { std::this_thread::sleep_for(std::chrono::milliseconds(1)); } +inline void rest() { + invoke_waiting([] { std::this_thread::sleep_for(std::chrono::milliseconds(1)); }); +} /**************************************************************************************************/ @@ -41,9 +44,11 @@ void test0(stlab::schedule_mode mode) { dq([&]() noexcept { strout(" d1 ( 3)"); }); - b([&]() { strout(" b2 ( 4)"); }) - .then(stlab::immediate_executor, [&]() { strout(" b2.1 ( 4.1)"); }) - .detach(); + b([&]() { + strout(" b2 ( 4)"); + }).then(stlab::immediate_executor, [&]() { + strout(" b2.1 ( 4.1)"); + }).detach(); cq([&]() noexcept { strout(" c1 ( 5)"); }); @@ -103,9 +108,8 @@ class test_hash_t { static std::mutex m; std::lock_guard l(m); - std::cout << std::hex << _name << " need: " - << "0x" << expected << " have: " - << "0x" << _h << "\n" + std::cout << std::hex << _name << " need: " << "0x" << expected << " have: " << "0x" << _h + << "\n" << std::dec; } @@ -128,8 +132,8 @@ struct serial_hash { std::atomic _c{0}; test_hash_t _h; - explicit serial_hash(std::string s, std::uint64_t e, stlab::schedule_mode mode) - : _q{stlab::default_executor, mode}, _h(std::move(s), e) {} + explicit serial_hash(std::string s, std::uint64_t e, stlab::schedule_mode mode) : + _q{stlab::default_executor, mode}, _h(std::move(s), e) {} void operator()(std::string s, std::uint64_t e) { _q.executor()([this, _e = e, _s = std::move(s)]() noexcept { diff --git a/test/tuple_test.cpp b/test/tuple_test.cpp index 562dc6905..c2dfcd6e7 100644 --- a/test/tuple_test.cpp +++ b/test/tuple_test.cpp @@ -115,8 +115,7 @@ BOOST_AUTO_TEST_CASE(future_when_all_int_int) { [](auto... args) { for_each_argument([](auto x) { cout << x << "\n"; }, args...); }, fi(), fi()); - while (!f.get_try()) - std::this_thread::sleep_for(std::chrono::milliseconds(1)); + await(std::move(f)); } /**************************************************************************************************/ @@ -126,8 +125,7 @@ BOOST_AUTO_TEST_CASE(future_when_all_void) { auto f = when_all(stlab::default_executor, []() { cout << "done!\n"; }, fv()); - while (!f.get_try()) - std::this_thread::sleep_for(std::chrono::milliseconds(1)); + await(std::move(f)); } /**************************************************************************************************/ @@ -144,8 +142,7 @@ BOOST_AUTO_TEST_CASE(future_when_all_void_int) { [](auto... args) { for_each_argument([](auto x) { cout << x << "\n"; }, args...); }, fv(), fi()); - while (!f.get_try()) - std::this_thread::sleep_for(std::chrono::milliseconds(1)); + await(std::move(f)); } /**************************************************************************************************/ @@ -162,8 +159,7 @@ BOOST_AUTO_TEST_CASE(future_when_all_int_void) { [](auto... args) { for_each_argument([](auto x) { cout << x << "\n"; }, args...); }, fi(), fv()); - while (!f.get_try()) - std::this_thread::sleep_for(std::chrono::milliseconds(1)); + await(std::move(f)); } /**************************************************************************************************/ @@ -181,8 +177,7 @@ BOOST_AUTO_TEST_CASE(future_when_all_int_void_string_void_bool_void) { [](auto... args) { for_each_argument([](auto x) { cout << x << "\n"; }, args...); }, fi(), fv(), fs(), fv(), fb(), fv()); - while (!f.get_try()) - std::this_thread::sleep_for(std::chrono::milliseconds(1)); + await(std::move(f)); } /**************************************************************************************************/ @@ -194,8 +189,7 @@ BOOST_AUTO_TEST_CASE(future_when_any_void) { stlab::default_executor, [](size_t index) { std::cout << "f: " << index << '\n'; }, fv(), fv(), fv(), fv(), fv(), fv()); - while (!f.get_try()) - std::this_thread::sleep_for(std::chrono::milliseconds(1)); + await(std::move(f)); } /**************************************************************************************************/