From 67106ebaab7a644a9bdb5d6e6b0a3f4ad1d0e4f7 Mon Sep 17 00:00:00 2001 From: Mohammad Nejati Date: Thu, 13 Nov 2025 19:36:06 +0000 Subject: [PATCH] Add tests for saved_handler when cancellation_slot::emplace throws --- test/beast/core/saved_handler.cpp | 67 ++++++++++++++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-) diff --git a/test/beast/core/saved_handler.cpp b/test/beast/core/saved_handler.cpp index d1816d24..0a1aa02c 100644 --- a/test/beast/core/saved_handler.cpp +++ b/test/beast/core/saved_handler.cpp @@ -101,6 +101,54 @@ public: } }; + class throwing_cancellation_slot + { + public: + throwing_cancellation_slot() + { + } + + template + CancellationHandler& emplace(Args&&...) + { + BOOST_THROW_EXCEPTION(std::exception{}); + } + + template + CancellationHandler& assign(CancellationHandler&&) + { + BOOST_THROW_EXCEPTION(std::exception{}); + } + + void clear() + { + } + + bool is_connected() const noexcept + { + return true; + } + + bool has_handler() const noexcept + { + return false; + } + + friend constexpr bool operator==( + const throwing_cancellation_slot&, + const throwing_cancellation_slot&) noexcept + { + return false; + } + + friend constexpr bool operator!=( + const throwing_cancellation_slot&, + const throwing_cancellation_slot&) noexcept + { + return false; + } + }; + void testSavedHandler() { @@ -198,7 +246,7 @@ public: net::cancellation_signal sig; try - { + { sh.emplace( net::bind_cancellation_slot( sig.slot(), @@ -212,6 +260,23 @@ public: BEAST_EXPECT(!sig.slot().has_handler()); BEAST_EXPECT(! sh.has_value()); } + { + saved_handler sh; + + try + { + sh.emplace( + net::bind_cancellation_slot( + throwing_cancellation_slot(), + unhandler{})); + fail(); + } + catch(std::exception const&) + { + pass(); + } + BEAST_EXPECT(! sh.has_value()); + } } void