From 33e4ad49f3e0a8423398c85c489b54425fc0ce90 Mon Sep 17 00:00:00 2001 From: Yingxin Cheng Date: Thu, 12 Sep 2019 15:17:21 +0800 Subject: [PATCH] test/crimson: add timeout feature for blockers to fail Signed-off-by: Yingxin Cheng --- src/crimson/net/Interceptor.h | 26 ++++++++++++++++++-------- src/test/crimson/test_messenger.cc | 12 ++++++++---- 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/src/crimson/net/Interceptor.h b/src/crimson/net/Interceptor.h index 5e61e1c0261..7bc07cc9b84 100644 --- a/src/crimson/net/Interceptor.h +++ b/src/crimson/net/Interceptor.h @@ -5,6 +5,7 @@ #include #include +#include #include "Fwd.h" #include "msg/async/frames_v2.h" @@ -50,8 +51,8 @@ inline std::ostream& operator<<(std::ostream& out, const bp_action_t& action) { } class socket_blocker { - std::optional> p_blocked; - std::optional> p_unblocked; + std::optional p_blocked; + std::optional p_unblocked; public: seastar::future<> wait_blocked() { @@ -59,25 +60,34 @@ class socket_blocker { if (p_unblocked) { return seastar::now(); } else { - p_blocked = seastar::promise<>(); - return p_blocked->get_future(); + p_blocked = seastar::abort_source(); + return seastar::sleep_abortable(10s, *p_blocked).then([this] { + throw std::runtime_error( + "Timeout (10s) in socket_blocker::wait_blocked()"); + }).handle_exception_type([] (const seastar::sleep_aborted& e) { + // wait done! + }); } } seastar::future<> block() { if (p_blocked) { - p_blocked->set_value(); + p_blocked->request_abort(); p_blocked = std::nullopt; } ceph_assert(!p_unblocked); - p_unblocked = seastar::promise<>(); - return p_unblocked->get_future(); + p_unblocked = seastar::abort_source(); + return seastar::sleep_abortable(10s, *p_unblocked).then([this] { + ceph_abort("Timeout (10s) in socket_blocker::block()"); + }).handle_exception_type([] (const seastar::sleep_aborted& e) { + // wait done! + }); } void unblock() { ceph_assert(!p_blocked); ceph_assert(p_unblocked); - p_unblocked->set_value(); + p_unblocked->request_abort(); p_unblocked = std::nullopt; } }; diff --git a/src/test/crimson/test_messenger.cc b/src/test/crimson/test_messenger.cc index 4b16be518ba..f3bdb106dd9 100644 --- a/src/test/crimson/test_messenger.cc +++ b/src/test/crimson/test_messenger.cc @@ -730,7 +730,7 @@ struct TestInterceptor : public Interceptor { std::map breakpoints_counter; std::map conns; ConnResults results; - std::optional> signal; + std::optional signal; TestInterceptor() = default; // only used for copy breakpoint configurations @@ -768,13 +768,17 @@ struct TestInterceptor : public Interceptor { seastar::future<> wait() { assert(!signal); - signal = seastar::promise<>(); - return signal->get_future(); + signal = seastar::abort_source(); + return seastar::sleep_abortable(10s, *signal).then([this] { + throw std::runtime_error("Timeout (10s) in TestInterceptor::wait()"); + }).handle_exception_type([] (const seastar::sleep_aborted& e) { + // wait done! + }); } void notify() { if (signal) { - signal->set_value(); + signal->request_abort(); signal = std::nullopt; } } -- 2.39.5