Skip to content

Commit

Permalink
Switch to partitioned transport test
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Carroll <[email protected]>
  • Loading branch information
mjcarroll committed Jan 25, 2024
1 parent 92d02dc commit 769f9c4
Show file tree
Hide file tree
Showing 26 changed files with 131 additions and 423 deletions.
25 changes: 7 additions & 18 deletions test/integration/authPubSub.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@

using namespace gz;

static std::string partition; // NOLINT(*)
using authPubSub = testing::PartitionedTransportTest;

static std::string g_topic = "/foo"; // NOLINT(*)

//////////////////////////////////////////////////
TEST(authPubSub, InvalidAuth)
TEST_F(authPubSub, InvalidAuth)
{
// Setup the username and password for this test
ASSERT_TRUE(gz::utils::setenv("GZ_TRANSPORT_USERNAME", "admin"));
Expand All @@ -48,9 +49,10 @@ TEST(authPubSub, InvalidAuth)
// No subscribers yet.
EXPECT_FALSE(pub.HasConnections());

auto pi = gz::utils::Subprocess(
{test_executables::kAuthPubSubSubscriberInvalid,
partition, "bad", "invalid"});
this->SpawnSubprocess({test_executables::kAuthPubSubSubscriberInvalid}, {
{"GZ_TRANSPORT_USERNAME", "bad"},
{"GZ_TRANSPORT_PASSWORD", "invalid"},
});

msgs::Int32 msg;
msg.set_data(1);
Expand All @@ -69,16 +71,3 @@ TEST(authPubSub, InvalidAuth)
std::this_thread::sleep_for(std::chrono::milliseconds(500));
}
}

//////////////////////////////////////////////////
int main(int argc, char **argv)
{
// Get a random partition name.
partition = testing::getRandomNumber();

// Set the partition name for this process.
gz::utils::setenv("GZ_PARTITION", partition);

::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
21 changes: 4 additions & 17 deletions test/integration/scopedTopic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,18 @@

using namespace gz;

static std::string partition; // NOLINT(*)
using ScopedTopicTest = testing::PartitionedTransportTest;

static std::string g_topic = "/foo"; // NOLINT(*)
static int data = 5;

//////////////////////////////////////////////////
/// \brief Two different nodes, each one running in a different process. The
/// publisher advertises the topic as "process". This test checks that the topic
/// is not seen by the other node running in a different process.
TEST(ScopedTopicTest, ProcessTest)
TEST_F(ScopedTopicTest, ProcessTest)
{
auto pi = gz::utils::Subprocess(
{test_executables::kScopedTopicSubscriber, partition});
this->SpawnSubprocess({test_executables::kScopedTopicSubscriber});

msgs::Int32 msg;
msg.set_data(data);
Expand All @@ -59,16 +59,3 @@ TEST(ScopedTopicTest, ProcessTest)
std::this_thread::sleep_for(std::chrono::milliseconds(500));
EXPECT_TRUE(pub.Publish(msg));
}

//////////////////////////////////////////////////
int main(int argc, char **argv)
{
// Get a random partition name.
partition = testing::getRandomNumber();

// Set the partition name for this process.
gz::utils::setenv("GZ_PARTITION", partition);

::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
19 changes: 4 additions & 15 deletions test/integration/statistics.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@

using namespace gz;

using topicStatistics = testing::PartitionedTransportTest;

static int statisticsCount = 0;

void cb(const msgs::StringMsg & /*_msg*/)
Expand All @@ -43,8 +45,9 @@ void statsCb(const msgs::Metric & /*_msg*/)
statisticsCount++;
}

TEST(topicStatistics, SingleProcessPublishStatistics)
TEST_F(topicStatistics, SingleProcessPublishStatistics)
{
ASSERT_TRUE(gz::utils::setenv("GZ_TRANSPORT_TOPIC_STATISTICS", "1"));
statisticsCount = 0;
std::string topic = "/foo";
transport::Node node;
Expand Down Expand Up @@ -74,17 +77,3 @@ TEST(topicStatistics, SingleProcessPublishStatistics)
EXPECT_EQ(0, statisticsCount);
EXPECT_EQ(std::nullopt, node.TopicStats(topic));
}

//////////////////////////////////////////////////
int main(int argc, char **argv)
{
// Get a random partition name.
std::string partition = testing::getRandomNumber();

// Set the partition name for this process.
gz::utils::setenv("GZ_PARTITION", partition);
gz::utils::setenv("GZ_TRANSPORT_TOPIC_STATISTICS", "1");

::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,13 @@

#include <chrono>
#include <string>
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable: 4251)
#endif
#include <gz/msgs/int32.pb.h>
#ifdef _MSC_VER
#pragma warning(pop)
#endif
#ifdef _WIN32
#include <filesystem>
#endif

#include "gz/transport/Node.hh"

#include <gz/utils/Environment.hh>

#include "gtest/gtest.h"
#include "test_config.hh"

using namespace gz;

Expand Down Expand Up @@ -76,22 +65,6 @@ TEST(authProcPubSub, PubSubTwoProcsTwoNodesSubscriber)
//////////////////////////////////////////////////
int main(int argc, char **argv)
{
if (argc != 4)
{
std::cerr << "Partition name, username, and password have not be passed as "
<< "arguments" << std::endl;
return -1;
}

// Set the partition name for this test.
gz::utils::setenv("GZ_PARTITION", argv[1]);

// Set the username for this test.
gz::utils::setenv("GZ_TRANSPORT_USERNAME", argv[2]);

// Set the password for this test.
gz::utils::setenv("GZ_TRANSPORT_PASSWORD", argv[3]);

::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
20 changes: 1 addition & 19 deletions test/integration/test_executables/fastPub_aux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,12 @@
*/
#include <chrono>
#include <string>
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable: 4251)
#endif
#include <gz/msgs/vector3d.pb.h>
#ifdef _MSC_VER
#pragma warning(pop)
#endif

#include "gz/transport/Node.hh"

#include <gz/utils/Environment.hh>

#include "test_config.hh"

using namespace gz;

static std::string g_topic = "/foo"; // NOLINT(*)
Expand All @@ -52,16 +43,7 @@ void advertiseAndPublish()
}

//////////////////////////////////////////////////
int main(int argc, char **argv)
int main(int, char **)
{
if (argc != 2)
{
std::cerr << "Partition name has not be passed as argument" << std::endl;
return -1;
}

// Set the partition name for this test.
gz::utils::setenv("GZ_PARTITION", argv[1]);

advertiseAndPublish();
}
13 changes: 1 addition & 12 deletions test/integration/test_executables/pub_aux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@

#include <gz/utils/Environment.hh>

#include "test_config.hh"

using namespace gz;

static std::string g_topic = "/foo"; // NOLINT(*)
Expand All @@ -53,16 +51,7 @@ void advertiseAndPublish()
}

//////////////////////////////////////////////////
int main(int argc, char **argv)
int main(int, char **)
{
if (argc < 2)
{
std::cerr << "Partition name has not be passed as argument" << std::endl;
return -1;
}

// Set the partition name for this test.
gz::utils::setenv("GZ_PARTITION", argv[1]);

advertiseAndPublish();
}
12 changes: 1 addition & 11 deletions test/integration/test_executables/pub_aux_throttled.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include <gz/utils/Environment.hh>

#include "gtest/gtest.h"
#include "test_config.hh"

using namespace gz;

Expand Down Expand Up @@ -55,16 +54,7 @@ void advertiseAndPublish()
}

//////////////////////////////////////////////////
int main(int argc, char **argv)
int main(int, char **)
{
if (argc < 2)
{
std::cerr << "Partition name has not be passed as argument" << std::endl;
return -1;
}

// Set the partition name for this test.
gz::utils::setenv("GZ_PARTITION", argv[1]);

advertiseAndPublish();
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,6 @@ TEST(ScopedTopicTest, SubscriberTest)
//////////////////////////////////////////////////
int main(int argc, char **argv)
{
if (argc != 2)
{
std::cerr << "Partition name has not be passed as argument" << std::endl;
return -1;
}

// Set the partition name for this test.
gz::utils::setenv("GZ_PARTITION", argv[1]);

::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
11 changes: 0 additions & 11 deletions test/integration/test_executables/twoProcsPubSubSubscriber_aux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include <gz/utils/Environment.hh>

#include "gtest/gtest.h"
#include "test_config.hh"

using namespace gz;

Expand Down Expand Up @@ -153,16 +152,6 @@ TEST(twoProcPubSub, PubSubTwoProcsTwoNodesSubscriber)
//////////////////////////////////////////////////
int main(int argc, char **argv)
{
if (argc != 2)
{
std::cerr << "Partition name has not be passed as argument" << std::endl;
return -1;
}

// Set the partition name for this test.
gz::utils::setenv("GZ_PARTITION", argv[1]);
gz::utils::setenv("GZ_TRANSPORT_TOPIC_STATISTICS", "1");

::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
13 changes: 1 addition & 12 deletions test/integration/test_executables/twoProcsPublisher_aux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@

#include <gz/utils/Environment.hh>

#include "test_config.hh"

using namespace gz;

static std::string g_topic = "/foo"; // NOLINT(*)
Expand All @@ -49,16 +47,7 @@ void advertiseAndPublish()
}

//////////////////////////////////////////////////
int main(int argc, char **argv)
int main(int, char **)
{
if (argc != 2)
{
std::cerr << "Partition name has not be passed as argument" << std::endl;
return -1;
}

// Set the partition name for this test.
gz::utils::setenv("GZ_PARTITION", argv[1]);

advertiseAndPublish();
}
10 changes: 0 additions & 10 deletions test/integration/test_executables/twoProcsSrvCallReplierInc_aux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include <gz/utils/Environment.hh>

#include "gtest/gtest.h"
#include "test_config.hh"

using namespace gz;

Expand Down Expand Up @@ -59,15 +58,6 @@ TEST(twoProcSrvCallReplierAux, SrvProcReplier)
//////////////////////////////////////////////////
int main(int argc, char **argv)
{
if (argc != 2)
{
std::cerr << "Partition name has not be passed as argument" << std::endl;
return -1;
}

// Set the partition name for this test.
gz::utils::setenv("GZ_PARTITION", argv[1]);

::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
12 changes: 1 addition & 11 deletions test/integration/test_executables/twoProcsSrvCallReplier_aux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include <gz/utils/Environment.hh>

#include "gtest/gtest.h"
#include "test_config.hh"

using namespace gz;

Expand All @@ -47,16 +46,7 @@ void runReplier()
}

//////////////////////////////////////////////////
int main(int argc, char **argv)
int main(int, char **)
{
if (argc != 2)
{
std::cerr << "Partition name has not be passed as argument" << std::endl;
return -1;
}

// Set the partition name for this test.
gz::utils::setenv("GZ_PARTITION", argv[1]);

runReplier();
}
Loading

0 comments on commit 769f9c4

Please sign in to comment.