From 5efc81c956bcb55b919d44173581cac54aa5c8ab Mon Sep 17 00:00:00 2001 From: Michael Carroll Date: Mon, 29 Jan 2024 18:24:56 +0000 Subject: [PATCH] Test with and without topic statistics Signed-off-by: Michael Carroll --- .../twoProcsPubSubSubscriber_aux.cc | 1 - test/integration/twoProcsPubSub.cc | 38 ++++++++++++------- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/test/integration/test_executables/twoProcsPubSubSubscriber_aux.cc b/test/integration/test_executables/twoProcsPubSubSubscriber_aux.cc index f24fc1dc..db19e94f 100644 --- a/test/integration/test_executables/twoProcsPubSubSubscriber_aux.cc +++ b/test/integration/test_executables/twoProcsPubSubSubscriber_aux.cc @@ -152,7 +152,6 @@ TEST(twoProcPubSub, PubSubTwoProcsTwoNodesSubscriber) ////////////////////////////////////////////////// int main(int argc, char **argv) { - gz::utils::setenv("GZ_TRANSPORT_TOPIC_STATISTICS", "1"); ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } diff --git a/test/integration/twoProcsPubSub.cc b/test/integration/twoProcsPubSub.cc index 2d8b77df..410781fd 100644 --- a/test/integration/twoProcsPubSub.cc +++ b/test/integration/twoProcsPubSub.cc @@ -32,7 +32,15 @@ using namespace gz; -using twoProcPubSub = testing::PartitionedTransportTest; +class twoProcPubSub: public testing::PartitionedTransportTest, + public testing::WithParamInterface +{ + protected: void SetUp() override { + testing::PartitionedTransportTest::SetUp(); + gz::utils::setenv("GZ_TRANSPORT_TOPIC_STATISTICS", + GetParam() ? "1" : "0"); + } +}; static std::string g_FQNPartition; // NOLINT(*) static const std::string g_topic = "/foo"; // NOLINT(*) @@ -106,7 +114,7 @@ void cbRaw(const char * /*_msgData*/, const size_t /*_size*/, /// subscriber process there are two nodes. Both should receive the message. /// After some time one of them unsubscribe. After that check that only one /// node receives the message. -TEST_F(twoProcPubSub, PubSubTwoProcsThreeNodes) +TEST_P(twoProcPubSub, PubSubTwoProcsThreeNodes) { transport::Node node; auto pub = node.Advertise(g_topic); @@ -138,7 +146,7 @@ TEST_F(twoProcPubSub, PubSubTwoProcsThreeNodes) ////////////////////////////////////////////////// /// \brief This is the same as the last test, but we use PublishRaw(~) instead /// of Publish(~). -TEST_F(twoProcPubSub, RawPubSubTwoProcsThreeNodes) +TEST_P(twoProcPubSub, RawPubSubTwoProcsThreeNodes) { transport::Node node; auto pub = node.Advertise(g_topic); @@ -173,7 +181,7 @@ TEST_F(twoProcPubSub, RawPubSubTwoProcsThreeNodes) ////////////////////////////////////////////////// /// \brief Check that a message is not received if the callback does not use /// the advertised types. -TEST_F(twoProcPubSub, PubSubWrongTypesOnSubscription) +TEST_P(twoProcPubSub, PubSubWrongTypesOnSubscription) { this->SpawnSubprocess({test_executables::kTwoProcsPublisher}); @@ -193,7 +201,7 @@ TEST_F(twoProcPubSub, PubSubWrongTypesOnSubscription) ////////////////////////////////////////////////// /// \brief Same as above, but using a raw subscription. -TEST_F(twoProcPubSub, PubRawSubWrongTypesOnSubscription) +TEST_P(twoProcPubSub, PubRawSubWrongTypesOnSubscription) { this->SpawnSubprocess({test_executables::kTwoProcsPublisher}); @@ -218,7 +226,7 @@ TEST_F(twoProcPubSub, PubRawSubWrongTypesOnSubscription) /// advertised type). The second subscriber uses the correct callback. The third /// uses a generic callback. Check that only two of the callbacks are executed /// (correct and generic). -TEST_F(twoProcPubSub, PubSubWrongTypesTwoSubscribers) +TEST_P(twoProcPubSub, PubSubWrongTypesTwoSubscribers) { this->SpawnSubprocess({test_executables::kTwoProcsPublisher}); @@ -250,7 +258,7 @@ TEST_F(twoProcPubSub, PubSubWrongTypesTwoSubscribers) /// match the advertised type). The second subscriber requests the correct type. /// The third accepts the generic (default) type. Check that only two of the /// callbacks are executed (correct and generic). -TEST_F(twoProcPubSub, PubSubWrongTypesTwoRawSubscribers) +TEST_P(twoProcPubSub, PubSubWrongTypesTwoRawSubscribers) { this->SpawnSubprocess({test_executables::kTwoProcsPublisher}); @@ -306,7 +314,7 @@ TEST_F(twoProcPubSub, PubSubWrongTypesTwoRawSubscribers) /// subscribes to a topic and the other advertises, publishes a message and /// terminates. This test checks that the subscriber doesn't get affected by /// the prompt termination of the publisher. -TEST_F(twoProcPubSub, FastPublisher) +TEST_P(twoProcPubSub, FastPublisher) { this->SpawnSubprocess({test_executables::kFastPub}); @@ -321,7 +329,7 @@ TEST_F(twoProcPubSub, FastPublisher) /// \brief This test creates one publisher and one subscriber on different /// processes. The publisher publishes at higher frequency than the rate set /// by the subscriber. -TEST_F(twoProcPubSub, SubThrottled) +TEST_P(twoProcPubSub, SubThrottled) { this->SpawnSubprocess({test_executables::kPub}); @@ -346,7 +354,7 @@ TEST_F(twoProcPubSub, SubThrottled) ////////////////////////////////////////////////// /// \brief This test creates one publisher and one subscriber on different /// processes. The publisher publishes at a throttled frequency. -TEST_F(twoProcPubSub, PubThrottled) +TEST_P(twoProcPubSub, PubThrottled) { this->SpawnSubprocess({test_executables::kPubThrottled}); @@ -369,7 +377,7 @@ TEST_F(twoProcPubSub, PubThrottled) ////////////////////////////////////////////////// /// \brief Check that a message is received after Advertise->Subscribe->Publish /// using a callback that accepts message information. -TEST_F(twoProcPubSub, PubSubMessageInfo) +TEST_P(twoProcPubSub, PubSubMessageInfo) { this->SpawnSubprocess({test_executables::kTwoProcsPublisher}); reset(); @@ -390,7 +398,7 @@ TEST_F(twoProcPubSub, PubSubMessageInfo) /// \brief This test spawns two nodes on different processes. One of the nodes /// advertises a topic and the other uses TopicList() for getting the list of /// available topics. -TEST_F(twoProcPubSub, TopicList) +TEST_P(twoProcPubSub, TopicList) { this->SpawnSubprocess({test_executables::kTwoProcsPublisher}); @@ -435,7 +443,7 @@ TEST_F(twoProcPubSub, TopicList) /// \brief This test spawns two nodes on different processes. One of the nodes /// advertises a topic and the other uses TopicInfo() for getting information /// about the topic. -TEST_F(twoProcPubSub, TopicInfo) +TEST_P(twoProcPubSub, TopicInfo) { this->SpawnSubprocess({test_executables::kTwoProcsPublisher}); @@ -459,3 +467,7 @@ TEST_F(twoProcPubSub, TopicInfo) reset(); } + +INSTANTIATE_TEST_SUITE_P(TransportStatistics, + twoProcPubSub, + testing::Bool());