From 3a41291baf68ab2111dba85e9e255c8e678930dd Mon Sep 17 00:00:00 2001 From: Aleksey Loginov Date: Mon, 23 Sep 2024 00:55:12 +0300 Subject: [PATCH 1/4] fix new_thread join --- src/rpp/rpp/schedulers/new_thread.hpp | 6 +----- src/tests/rpp/test_scheduler.cpp | 17 +++++++++++++---- src/tests/utils/rpp_trompeloil.hpp | 3 ++- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/rpp/rpp/schedulers/new_thread.hpp b/src/rpp/rpp/schedulers/new_thread.hpp index c48925071..5cefa7ed9 100644 --- a/src/rpp/rpp/schedulers/new_thread.hpp +++ b/src/rpp/rpp/schedulers/new_thread.hpp @@ -44,11 +44,7 @@ namespace rpp::schedulers m_state->is_stoping = true; } m_state->cv.notify_all(); - - if (m_thread.get_id() != std::this_thread::get_id()) - m_thread.join(); - else - m_thread.detach(); + m_thread.detach(); } template Fn> diff --git a/src/tests/rpp/test_scheduler.cpp b/src/tests/rpp/test_scheduler.cpp index d8627c990..3cca3efb4 100644 --- a/src/tests/rpp/test_scheduler.cpp +++ b/src/tests/rpp/test_scheduler.cpp @@ -22,6 +22,7 @@ #include #include "rpp/disposables/fwd.hpp" +#include "rpp_trompeloil.hpp" #include #include @@ -735,14 +736,22 @@ TEST_CASE("new_thread utilized current_thread") TEST_CASE("new_thread works till end") { - auto mock = mock_observer_strategy{}; + auto mock = mock_observer{}; + trompeloeil::sequence s{}; - rpp::source::just(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) + const auto vals = std::array{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + + REQUIRE_CALL(*mock, on_next_lvalue(trompeloeil::_)).TIMES(10).IN_SEQUENCE(s); + + const auto last = NAMED_REQUIRE_CALL(*mock, on_completed()).IN_SEQUENCE(s); + + rpp::source::from_iterable(vals) | rpp::operators::subscribe_on(rpp::schedulers::new_thread{}) - | rpp::operators::as_blocking() | rpp::operators::subscribe(mock); - CHECK(mock.get_received_values().size() == 10); + CHECK(!last->is_satisfied()); + + wait(last); } TEST_CASE("run_loop scheduler dispatches tasks only manually") diff --git a/src/tests/utils/rpp_trompeloil.hpp b/src/tests/utils/rpp_trompeloil.hpp index f2fb3b7f1..712cf907b 100644 --- a/src/tests/utils/rpp_trompeloil.hpp +++ b/src/tests/utils/rpp_trompeloil.hpp @@ -75,7 +75,8 @@ class mock_observer std::shared_ptr m_impl = std::make_shared(); }; -inline void wait(const std::unique_ptr& e) +template +inline void wait(const std::unique_ptr& e) { while (!e->is_satisfied()) { From 12e7c297ad286d7585bc947f1b1d06fd27dae2b0 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 22 Sep 2024 21:55:38 +0000 Subject: [PATCH 2/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/tests/rpp/test_scheduler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tests/rpp/test_scheduler.cpp b/src/tests/rpp/test_scheduler.cpp index 3cca3efb4..980822e0b 100644 --- a/src/tests/rpp/test_scheduler.cpp +++ b/src/tests/rpp/test_scheduler.cpp @@ -736,7 +736,7 @@ TEST_CASE("new_thread utilized current_thread") TEST_CASE("new_thread works till end") { - auto mock = mock_observer{}; + auto mock = mock_observer{}; trompeloeil::sequence s{}; const auto vals = std::array{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; From 87c1ad0e152a2fc5071f889bd11c1fbbfe75c377 Mon Sep 17 00:00:00 2001 From: Aleksey Loginov Date: Wed, 25 Sep 2024 20:44:35 +0300 Subject: [PATCH 3/4] fix test --- src/tests/rpp/test_scheduler.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/tests/rpp/test_scheduler.cpp b/src/tests/rpp/test_scheduler.cpp index 980822e0b..05679aa23 100644 --- a/src/tests/rpp/test_scheduler.cpp +++ b/src/tests/rpp/test_scheduler.cpp @@ -743,7 +743,14 @@ TEST_CASE("new_thread works till end") REQUIRE_CALL(*mock, on_next_lvalue(trompeloeil::_)).TIMES(10).IN_SEQUENCE(s); - const auto last = NAMED_REQUIRE_CALL(*mock, on_completed()).IN_SEQUENCE(s); + auto done = std::make_shared(); + + const auto last = NAMED_REQUIRE_CALL(*mock, on_completed()).LR_SIDE_EFFECT({ + thread_local rpp::utils::finally_action s_a{[done] { + done->store(true); + }}; + }) + .IN_SEQUENCE(s); rpp::source::from_iterable(vals) | rpp::operators::subscribe_on(rpp::schedulers::new_thread{}) @@ -752,6 +759,8 @@ TEST_CASE("new_thread works till end") CHECK(!last->is_satisfied()); wait(last); + + while (!done->load()){}; } TEST_CASE("run_loop scheduler dispatches tasks only manually") From eb4e94fd864f2c9647be772fdc93458edfd39a2f Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 25 Sep 2024 17:45:39 +0000 Subject: [PATCH 4/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/tests/rpp/test_scheduler.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/tests/rpp/test_scheduler.cpp b/src/tests/rpp/test_scheduler.cpp index 05679aa23..32a8d6601 100644 --- a/src/tests/rpp/test_scheduler.cpp +++ b/src/tests/rpp/test_scheduler.cpp @@ -743,7 +743,7 @@ TEST_CASE("new_thread works till end") REQUIRE_CALL(*mock, on_next_lvalue(trompeloeil::_)).TIMES(10).IN_SEQUENCE(s); - auto done = std::make_shared(); + auto done = std::make_shared(); const auto last = NAMED_REQUIRE_CALL(*mock, on_completed()).LR_SIDE_EFFECT({ thread_local rpp::utils::finally_action s_a{[done] { @@ -760,7 +760,9 @@ TEST_CASE("new_thread works till end") wait(last); - while (!done->load()){}; + while (!done->load()) + { + }; } TEST_CASE("run_loop scheduler dispatches tasks only manually")