mirror of
https://github.com/XRPLF/clio.git
synced 2025-12-06 17:27:58 +00:00
feat: Async framework submit on strand/ctx (#2751)
This commit is contained in:
@@ -124,6 +124,6 @@ struct FakeRetryPolicy {
|
||||
void
|
||||
retry(Fn&& fn)
|
||||
{
|
||||
fn();
|
||||
std::invoke(std::forward<decltype(fn)>(fn));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -28,7 +28,6 @@
|
||||
#include <string_view>
|
||||
|
||||
namespace common::util {
|
||||
|
||||
class WithMockAssert : virtual public testing::Test {
|
||||
public:
|
||||
struct MockAssertException {
|
||||
@@ -48,30 +47,42 @@ public:
|
||||
~WithMockAssertNoThrow() override;
|
||||
};
|
||||
|
||||
namespace impl {
|
||||
template <typename T>
|
||||
struct MockGuard {
|
||||
T mock;
|
||||
~MockGuard()
|
||||
{
|
||||
::util::impl::OnAssert::resetAction();
|
||||
}
|
||||
};
|
||||
} // namespace impl
|
||||
|
||||
} // namespace common::util
|
||||
|
||||
#define EXPECT_CLIO_ASSERT_FAIL_WITH_MESSAGE(statement, message_regex) \
|
||||
if (dynamic_cast<common::util::WithMockAssert*>(this) != nullptr) { \
|
||||
EXPECT_THROW( \
|
||||
{ \
|
||||
try { \
|
||||
statement; \
|
||||
} catch (common::util::WithMockAssert::MockAssertException const& e) { \
|
||||
EXPECT_THAT(e.message, testing::ContainsRegex(message_regex)); \
|
||||
throw; \
|
||||
} \
|
||||
}, \
|
||||
common::util::WithMockAssert::MockAssertException \
|
||||
); \
|
||||
} else if (dynamic_cast<common::util::WithMockAssertNoThrow*>(this) != nullptr) { \
|
||||
testing::StrictMock<testing::MockFunction<void(std::string_view)>> callMock; \
|
||||
::util::impl::OnAssert::setAction([&callMock](std::string_view m) { callMock.Call(m); }); \
|
||||
EXPECT_CALL(callMock, Call(testing::ContainsRegex(message_regex))); \
|
||||
statement; \
|
||||
::util::impl::OnAssert::resetAction(); \
|
||||
} else { \
|
||||
std::cerr << "EXPECT_CLIO_ASSERT_FAIL_WITH_MESSAGE() can be used only inside test body" << std::endl; \
|
||||
std::terminate(); \
|
||||
#define EXPECT_CLIO_ASSERT_FAIL_WITH_MESSAGE(statement, message_regex) \
|
||||
if (dynamic_cast<common::util::WithMockAssert*>(this) != nullptr) { \
|
||||
EXPECT_THROW( \
|
||||
{ \
|
||||
try { \
|
||||
statement; \
|
||||
} catch (common::util::WithMockAssert::MockAssertException const& e) { \
|
||||
EXPECT_THAT(e.message, testing::ContainsRegex(message_regex)); \
|
||||
throw; \
|
||||
} \
|
||||
}, \
|
||||
common::util::WithMockAssert::MockAssertException \
|
||||
); \
|
||||
} else if (dynamic_cast<common::util::WithMockAssertNoThrow*>(this) != nullptr) { \
|
||||
using MockGuardType = \
|
||||
common::util::impl::MockGuard<testing::StrictMock<testing::MockFunction<void(std::string_view)>>>; \
|
||||
auto mockGuard = std::make_shared<MockGuardType>(); \
|
||||
::util::impl::OnAssert::setAction([mockGuard](std::string_view m) { mockGuard->mock.Call(m); }); \
|
||||
EXPECT_CALL(mockGuard->mock, Call(testing::ContainsRegex(message_regex))); \
|
||||
statement; \
|
||||
} else { \
|
||||
std::cerr << "EXPECT_CLIO_ASSERT_FAIL_WITH_MESSAGE() can be used only inside test body" << std::endl; \
|
||||
std::terminate(); \
|
||||
}
|
||||
|
||||
#define EXPECT_CLIO_ASSERT_FAIL(statement) EXPECT_CLIO_ASSERT_FAIL_WITH_MESSAGE(statement, ".*")
|
||||
|
||||
@@ -84,6 +84,7 @@ struct MockExecutionContext {
|
||||
(std::chrono::milliseconds, std::function<std::any()>),
|
||||
()
|
||||
);
|
||||
MOCK_METHOD(void, submit, (std::function<void()>), ());
|
||||
|
||||
MOCK_METHOD(MockStrand const&, makeStrand, (), ());
|
||||
MOCK_METHOD(void, stop, (), (const));
|
||||
|
||||
@@ -69,4 +69,5 @@ struct MockStrand {
|
||||
(std::chrono::milliseconds, std::function<std::any()>),
|
||||
(const)
|
||||
);
|
||||
MOCK_METHOD(void, submit, (std::function<void()>), (const));
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user