From 3b0f4902d95dbd09e292983683597569a16bfd19 Mon Sep 17 00:00:00 2001 From: Tor Egge Date: Mon, 11 Mar 2024 19:02:32 +0100 Subject: Rewrite messagebus RoutingContext unit test to gtest. --- messagebus/src/tests/routingcontext/CMakeLists.txt | 1 + .../src/tests/routingcontext/routingcontext.cpp | 74 ++++++++++------------ 2 files changed, 35 insertions(+), 40 deletions(-) diff --git a/messagebus/src/tests/routingcontext/CMakeLists.txt b/messagebus/src/tests/routingcontext/CMakeLists.txt index 96bf6dbe35e..932d0020a3e 100644 --- a/messagebus/src/tests/routingcontext/CMakeLists.txt +++ b/messagebus/src/tests/routingcontext/CMakeLists.txt @@ -5,5 +5,6 @@ vespa_add_executable(messagebus_routingcontext_test_app TEST DEPENDS messagebus_messagebus-test messagebus + GTest::gtest ) vespa_add_test(NAME messagebus_routingcontext_test_app COMMAND messagebus_routingcontext_test_app) diff --git a/messagebus/src/tests/routingcontext/routingcontext.cpp b/messagebus/src/tests/routingcontext/routingcontext.cpp index d81bada2bc6..c8bbc53a0df 100644 --- a/messagebus/src/tests/routingcontext/routingcontext.cpp +++ b/messagebus/src/tests/routingcontext/routingcontext.cpp @@ -9,7 +9,7 @@ #include #include #include -#include +#include #include @@ -17,6 +17,8 @@ using namespace mbus; using vespalib::make_string; +namespace { + static const duration TIMEOUT = 120s; class StringList : public std::vector { @@ -192,20 +194,6 @@ public: bool start(); }; -class Test : public vespalib::TestApp { -private: - static Message::UP createMessage(const string &msg); - -public: - int Main() override; - void testSingleDirective(TestData &data); - void testMoreDirectives(TestData &data); - void testRecipientsRemain(TestData &data); - void testConstRoute(TestData &data); -}; - -TEST_APPHOOK(Test); - TestData::TestData() : _slobrok(), _retryPolicy(std::make_shared()), @@ -240,28 +228,33 @@ TestData::start() return true; } -Message::UP -Test::createMessage(const string &msg) -{ - auto ret = std::make_unique(msg); - ret->getTrace().setLevel(9); - return ret; } -int -Test::Main() -{ - TEST_INIT("routingcontext_test"); +class RoutingContextTest : public testing::Test { +protected: + static std::shared_ptr _data; + RoutingContextTest(); + ~RoutingContextTest() override; + static void SetUpTestSuite(); + static void TearDownTestSuite(); +}; - TestData data; - ASSERT_TRUE(data.start()); +std::shared_ptr RoutingContextTest::_data; - testSingleDirective(data); TEST_FLUSH(); - testMoreDirectives(data); TEST_FLUSH(); - testRecipientsRemain(data); TEST_FLUSH(); - testConstRoute(data); TEST_FLUSH(); +RoutingContextTest::RoutingContextTest() = default; +RoutingContextTest::~RoutingContextTest() = default; - TEST_DONE(); +void +RoutingContextTest::SetUpTestSuite() +{ + _data = std::make_shared(); + ASSERT_TRUE(_data->start()); +} + +void +RoutingContextTest::TearDownTestSuite() +{ + _data.reset(); } //////////////////////////////////////////////////////////////////////////////// @@ -270,9 +263,9 @@ Test::Main() // //////////////////////////////////////////////////////////////////////////////// -void -Test::testSingleDirective(TestData &data) +TEST_F(RoutingContextTest, test_single_directive) { + auto& data = *_data; IProtocol::SP protocol(new SimpleProtocol()); auto &simple = dynamic_cast(*protocol); simple.addPolicyFactory("Custom", SimpleProtocol::IPolicyFactory::SP(new CustomPolicyFactory( @@ -295,9 +288,9 @@ Test::testSingleDirective(TestData &data) } } -void -Test::testMoreDirectives(TestData &data) +TEST_F(RoutingContextTest, test_more_directives) { + auto& data = *_data; IProtocol::SP protocol(new SimpleProtocol()); auto &simple = dynamic_cast(*protocol); simple.addPolicyFactory("Custom", SimpleProtocol::IPolicyFactory::SP(new CustomPolicyFactory( @@ -322,9 +315,9 @@ Test::testMoreDirectives(TestData &data) } } -void -Test::testRecipientsRemain(TestData &data) +TEST_F(RoutingContextTest, test_recipients_remain) { + auto& data = *_data; auto protocol = std::make_shared(); auto &simple = dynamic_cast(*protocol); simple.addPolicyFactory("First", std::make_shared(true, @@ -347,9 +340,9 @@ Test::testRecipientsRemain(TestData &data) } } -void -Test::testConstRoute(TestData &data) +TEST_F(RoutingContextTest, test_const_route) { + auto& data = *_data; auto protocol = std::make_shared(); auto &simple = dynamic_cast(*protocol); simple.addPolicyFactory("DocumentRouteSelector", @@ -371,3 +364,4 @@ Test::testConstRoute(TestData &data) } } +GTEST_MAIN_RUN_ALL_TESTS() -- cgit v1.2.3