Skip to content

Commit

Permalink
[eclipse-iceoryx#349] Add service name generator to be able to run te…
Browse files Browse the repository at this point in the history
…sts concurrently
  • Loading branch information
elfenpiff committed Oct 16, 2024
1 parent cd27eee commit 3a8b0ee
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 66 deletions.
35 changes: 14 additions & 21 deletions iceoryx2-ffi/cxx/tests/src/service_event_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
//
// SPDX-License-Identifier: Apache-2.0 OR MIT

#include <cstdlib>

#include "iox2/log.hpp"
#include "iox2/node.hpp"
#include "iox2/node_name.hpp"
#include "iox2/service.hpp"
Expand All @@ -24,8 +27,7 @@ constexpr iox::units::Duration TIMEOUT = iox::units::Duration::fromMilliseconds(
template <typename T>
struct ServiceEventTest : public ::testing::Test {
ServiceEventTest()
: service_name_value { "We all love the hypnotoad!" }
, service_name { ServiceName::create(service_name_value).expect("") }
: service_name { iox2_testing::generate_service_name() }
, node { NodeBuilder().create<T::TYPE>().expect("") }
, service { node.service_builder(service_name).event().create().expect("") }
, notifier { service.notifier_builder().create().expect("") }
Expand All @@ -37,7 +39,6 @@ struct ServiceEventTest : public ::testing::Test {
static std::atomic<size_t> event_id_counter;
static constexpr ServiceType TYPE = T::TYPE;
//NOLINTBEGIN(misc-non-private-member-variables-in-classes), required for tests
const char* service_name_value { nullptr };
ServiceName service_name;
Node<T::TYPE> node;
PortFactoryEvent<T::TYPE> service;
Expand All @@ -56,8 +57,7 @@ TYPED_TEST_SUITE(ServiceEventTest, iox2_testing::ServiceTypes);
TYPED_TEST(ServiceEventTest, created_service_does_exist) {
constexpr ServiceType SERVICE_TYPE = TestFixture::TYPE;

const auto* name_value = "First time we met, I saw the ocean, it was wet!";
const auto service_name = ServiceName::create(name_value).expect("");
const auto service_name = iox2_testing::generate_service_name();

ASSERT_FALSE(
Service<SERVICE_TYPE>::does_exist(service_name, Config::global_config(), MessagingPattern::Event).expect(""));
Expand All @@ -78,8 +78,7 @@ TYPED_TEST(ServiceEventTest, created_service_does_exist) {
TYPED_TEST(ServiceEventTest, creating_existing_service_fails) {
constexpr ServiceType SERVICE_TYPE = TestFixture::TYPE;

const auto* name_value = "First time we met, I saw the ocean, it was wet!";
const auto service_name = ServiceName::create(name_value).expect("");
const auto service_name = iox2_testing::generate_service_name();

auto node = NodeBuilder().create<SERVICE_TYPE>().expect("");
auto sut = node.service_builder(service_name).event().create().expect("");
Expand All @@ -94,8 +93,7 @@ TYPED_TEST(ServiceEventTest, service_settings_are_applied) {
constexpr uint64_t NUMBER_OF_NOTIFIERS = 5;
constexpr uint64_t NUMBER_OF_LISTENERS = 7;

const auto* name_value = "First time we met, I saw the ocean, it was wet!";
const auto service_name = ServiceName::create(name_value).expect("");
const auto service_name = iox2_testing::generate_service_name();

auto node = NodeBuilder().create<SERVICE_TYPE>().expect("");
auto sut = node.service_builder(service_name)
Expand All @@ -115,8 +113,7 @@ TYPED_TEST(ServiceEventTest, open_fails_with_incompatible_max_notifiers_requirem
constexpr ServiceType SERVICE_TYPE = TestFixture::TYPE;
constexpr uint64_t NUMBER_OF_NOTIFIERS = 5;

const auto* name_value = "First time we met, I saw the ocean, it was wet!";
const auto service_name = ServiceName::create(name_value).expect("");
const auto service_name = iox2_testing::generate_service_name();

auto node = NodeBuilder().create<SERVICE_TYPE>().expect("");
auto sut = node.service_builder(service_name).event().max_notifiers(NUMBER_OF_NOTIFIERS).create().expect("");
Expand All @@ -130,8 +127,7 @@ TYPED_TEST(ServiceEventTest, open_fails_with_incompatible_max_listeners_requirem
constexpr ServiceType SERVICE_TYPE = TestFixture::TYPE;
constexpr uint64_t NUMBER_OF_LISTENERS = 7;

const auto* name_value = "First time we met, I saw the ocean, it was wet!";
const auto service_name = ServiceName::create(name_value).expect("");
const auto service_name = iox2_testing::generate_service_name();

auto node = NodeBuilder().create<SERVICE_TYPE>().expect("");
auto sut = node.service_builder(service_name).event().max_listeners(NUMBER_OF_LISTENERS).create().expect("");
Expand All @@ -142,10 +138,10 @@ TYPED_TEST(ServiceEventTest, open_fails_with_incompatible_max_listeners_requirem
}

TYPED_TEST(ServiceEventTest, open_or_create_service_does_exist) {
iox2::set_log_level(LogLevel::TRACE);
constexpr ServiceType SERVICE_TYPE = TestFixture::TYPE;

const auto* name_value = "First time we met, I saw the ocean, it was wet!";
const auto service_name = ServiceName::create(name_value).expect("");
const auto service_name = iox2_testing::generate_service_name();

ASSERT_FALSE(
Service<SERVICE_TYPE>::does_exist(service_name, Config::global_config(), MessagingPattern::Event).expect(""));
Expand Down Expand Up @@ -180,8 +176,7 @@ TYPED_TEST(ServiceEventTest, open_or_create_service_does_exist) {
TYPED_TEST(ServiceEventTest, opening_non_existing_service_fails) {
constexpr ServiceType SERVICE_TYPE = TestFixture::TYPE;

const auto* name_value = "First time we met, I saw the ocean, it was wet!";
const auto service_name = ServiceName::create(name_value).expect("");
const auto service_name = iox2_testing::generate_service_name();

auto node = NodeBuilder().create<SERVICE_TYPE>().expect("");
auto sut = node.service_builder(service_name).event().open();
Expand All @@ -192,8 +187,7 @@ TYPED_TEST(ServiceEventTest, opening_non_existing_service_fails) {
TYPED_TEST(ServiceEventTest, opening_existing_service_works) {
constexpr ServiceType SERVICE_TYPE = TestFixture::TYPE;

const auto* name_value = "First time we met, I saw the ocean, it was wet!";
const auto service_name = ServiceName::create(name_value).expect("");
const auto service_name = iox2_testing::generate_service_name();

auto node = NodeBuilder().create<SERVICE_TYPE>().expect("");
auto sut_create = node.service_builder(service_name).event().create();
Expand All @@ -204,8 +198,7 @@ TYPED_TEST(ServiceEventTest, opening_existing_service_works) {
TYPED_TEST(ServiceEventTest, service_name_is_set) {
constexpr ServiceType SERVICE_TYPE = TestFixture::TYPE;

const auto* name_value = "Another one bites the toad.";
const auto service_name = ServiceName::create(name_value).expect("");
const auto service_name = iox2_testing::generate_service_name();

auto node = NodeBuilder().create<SERVICE_TYPE>().expect("");
auto sut = node.service_builder(service_name).event().create().expect("");
Expand Down
56 changes: 18 additions & 38 deletions iceoryx2-ffi/cxx/tests/src/service_publish_subscribe_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ TYPED_TEST_SUITE(ServicePublishSubscribeTest, iox2_testing::ServiceTypes);
TYPED_TEST(ServicePublishSubscribeTest, created_service_does_exist) {
constexpr ServiceType SERVICE_TYPE = TestFixture::TYPE;

const auto* name_value = "I am floating through the galaxy of my brain. Oh the colors!";
const auto service_name = ServiceName::create(name_value).expect("");
const auto service_name = iox2_testing::generate_service_name();

ASSERT_FALSE(
Service<SERVICE_TYPE>::does_exist(service_name, Config::global_config(), MessagingPattern::PublishSubscribe)
Expand All @@ -60,8 +59,7 @@ TYPED_TEST(ServicePublishSubscribeTest, created_service_does_exist) {
TYPED_TEST(ServicePublishSubscribeTest, creating_existing_service_fails) {
constexpr ServiceType SERVICE_TYPE = TestFixture::TYPE;

const auto* name_value = "I am floating through the galaxy of my brain. Oh the colors!";
const auto service_name = ServiceName::create(name_value).expect("");
const auto service_name = iox2_testing::generate_service_name();

ASSERT_FALSE(
Service<SERVICE_TYPE>::does_exist(service_name, Config::global_config(), MessagingPattern::PublishSubscribe)
Expand All @@ -78,8 +76,7 @@ TYPED_TEST(ServicePublishSubscribeTest, creating_existing_service_fails) {
TYPED_TEST(ServicePublishSubscribeTest, open_or_create_service_does_exist) {
constexpr ServiceType SERVICE_TYPE = TestFixture::TYPE;

const auto* name_value = "I am floating through the galaxy of my brain. Oh the colors!";
const auto service_name = ServiceName::create(name_value).expect("");
const auto service_name = iox2_testing::generate_service_name();

ASSERT_FALSE(
Service<SERVICE_TYPE>::does_exist(service_name, Config::global_config(), MessagingPattern::PublishSubscribe)
Expand Down Expand Up @@ -119,8 +116,7 @@ TYPED_TEST(ServicePublishSubscribeTest, open_or_create_service_does_exist) {
TYPED_TEST(ServicePublishSubscribeTest, opening_non_existing_service_fails) {
constexpr ServiceType SERVICE_TYPE = TestFixture::TYPE;

const auto* name_value = "I am floating through the galaxy of my brain. Oh the colors!";
const auto service_name = ServiceName::create(name_value).expect("");
const auto service_name = iox2_testing::generate_service_name();

auto node = NodeBuilder().create<SERVICE_TYPE>().expect("");
auto sut = node.service_builder(service_name).template publish_subscribe<uint64_t>().open();
Expand All @@ -131,8 +127,7 @@ TYPED_TEST(ServicePublishSubscribeTest, opening_non_existing_service_fails) {
TYPED_TEST(ServicePublishSubscribeTest, opening_existing_service_works) {
constexpr ServiceType SERVICE_TYPE = TestFixture::TYPE;

const auto* name_value = "I am floating through the galaxy of my brain. Oh the colors!";
const auto service_name = ServiceName::create(name_value).expect("");
const auto service_name = iox2_testing::generate_service_name();

auto node = NodeBuilder().create<SERVICE_TYPE>().expect("");
auto sut_create = node.service_builder(service_name).template publish_subscribe<uint64_t>().create();
Expand All @@ -143,8 +138,7 @@ TYPED_TEST(ServicePublishSubscribeTest, opening_existing_service_works) {
TYPED_TEST(ServicePublishSubscribeTest, opening_existing_service_with_wrong_payload_type_fails) {
constexpr ServiceType SERVICE_TYPE = TestFixture::TYPE;

const auto* name_value = "I am floating through the galaxy of my brain. Oh the colors!";
const auto service_name = ServiceName::create(name_value).expect("");
const auto service_name = iox2_testing::generate_service_name();

auto node = NodeBuilder().create<SERVICE_TYPE>().expect("");
auto sut_create = node.service_builder(service_name).template publish_subscribe<uint64_t>().create();
Expand All @@ -156,8 +150,7 @@ TYPED_TEST(ServicePublishSubscribeTest, opening_existing_service_with_wrong_payl
TYPED_TEST(ServicePublishSubscribeTest, open_or_create_existing_service_with_wrong_payload_type_fails) {
constexpr ServiceType SERVICE_TYPE = TestFixture::TYPE;

const auto* name_value = "I am floating through the galaxy of my brain. Oh the colors!";
const auto service_name = ServiceName::create(name_value).expect("");
const auto service_name = iox2_testing::generate_service_name();

auto node = NodeBuilder().create<SERVICE_TYPE>().expect("");
auto sut_create = node.service_builder(service_name).template publish_subscribe<uint64_t>().create();
Expand All @@ -169,8 +162,7 @@ TYPED_TEST(ServicePublishSubscribeTest, open_or_create_existing_service_with_wro
TYPED_TEST(ServicePublishSubscribeTest, send_copy_receive_works) {
constexpr ServiceType SERVICE_TYPE = TestFixture::TYPE;

const auto* name_value = "I am floating through the galaxy of my brain. Oh the colors!";
const auto service_name = ServiceName::create(name_value).expect("");
const auto service_name = iox2_testing::generate_service_name();

auto node = NodeBuilder().create<SERVICE_TYPE>().expect("");
auto service = node.service_builder(service_name).template publish_subscribe<uint64_t>().create().expect("");
Expand All @@ -189,8 +181,7 @@ TYPED_TEST(ServicePublishSubscribeTest, send_copy_receive_works) {
TYPED_TEST(ServicePublishSubscribeTest, loan_uninit_send_receive_works) {
constexpr ServiceType SERVICE_TYPE = TestFixture::TYPE;

const auto* name_value = "I am floating through the galaxy of my brain. Oh the colors!";
const auto service_name = ServiceName::create(name_value).expect("");
const auto service_name = iox2_testing::generate_service_name();

auto node = NodeBuilder().create<SERVICE_TYPE>().expect("");
auto service = node.service_builder(service_name).template publish_subscribe<uint64_t>().create().expect("");
Expand All @@ -211,8 +202,7 @@ TYPED_TEST(ServicePublishSubscribeTest, loan_uninit_send_receive_works) {
TYPED_TEST(ServicePublishSubscribeTest, loan_send_receive_works) {
constexpr ServiceType SERVICE_TYPE = TestFixture::TYPE;

const auto* name_value = "I am floating through the galaxy of my brain. Oh the colors!";
const auto service_name = ServiceName::create(name_value).expect("");
const auto service_name = iox2_testing::generate_service_name();

auto node = NodeBuilder().create<SERVICE_TYPE>().expect("");
auto service = node.service_builder(service_name).template publish_subscribe<uint64_t>().create().expect("");
Expand All @@ -233,8 +223,7 @@ TYPED_TEST(ServicePublishSubscribeTest, loan_send_receive_works) {
TYPED_TEST(ServicePublishSubscribeTest, update_connections_delivers_history) {
constexpr ServiceType SERVICE_TYPE = TestFixture::TYPE;

const auto* name_value = "Whoop here it is - the publishers historyyyy!";
const auto service_name = ServiceName::create(name_value).expect("");
const auto service_name = iox2_testing::generate_service_name();

auto node = NodeBuilder().create<SERVICE_TYPE>().expect("");
auto service = node.service_builder(service_name).template publish_subscribe<uint64_t>().create().expect("");
Expand Down Expand Up @@ -264,8 +253,7 @@ TYPED_TEST(ServicePublishSubscribeTest, setting_service_properties_works) {
constexpr uint64_t SUBSCRIBER_MAX_BUFFER_SIZE = 14;
constexpr uint64_t SUBSCRIBER_MAX_BORROWED_SAMPLES = 15;

const auto* name_value = "I am floating through the galaxy of my brain. Oh the colors!";
const auto service_name = ServiceName::create(name_value).expect("");
const auto service_name = iox2_testing::generate_service_name();

auto node = NodeBuilder().create<SERVICE_TYPE>().expect("");
auto service = node.service_builder(service_name)
Expand Down Expand Up @@ -295,8 +283,7 @@ TYPED_TEST(ServicePublishSubscribeTest, setting_service_properties_works) {
TYPED_TEST(ServicePublishSubscribeTest, safe_overflow_can_be_set) {
constexpr ServiceType SERVICE_TYPE = TestFixture::TYPE;

const auto* name_value = "I am floating through the galaxy of my brain. Oh the colors!";
const auto service_name = ServiceName::create(name_value).expect("");
const auto service_name = iox2_testing::generate_service_name();

auto node = NodeBuilder().create<SERVICE_TYPE>().expect("");

Expand All @@ -317,8 +304,7 @@ TYPED_TEST(ServicePublishSubscribeTest, open_fails_with_incompatible_publisher_r
constexpr ServiceType SERVICE_TYPE = TestFixture::TYPE;
constexpr uint64_t NUMBER_OF_PUBLISHERS = 11;

const auto* name_value = "I am floating through the galaxy of my brain. Oh the colors!";
const auto service_name = ServiceName::create(name_value).expect("");
const auto service_name = iox2_testing::generate_service_name();

auto node = NodeBuilder().create<SERVICE_TYPE>().expect("");
auto service = node.service_builder(service_name)
Expand All @@ -340,8 +326,7 @@ TYPED_TEST(ServicePublishSubscribeTest, open_fails_with_incompatible_subscriber_
constexpr ServiceType SERVICE_TYPE = TestFixture::TYPE;
constexpr uint64_t NUMBER_OF_SUBSCRIBERS = 12;

const auto* name_value = "I am floating through the galaxy of my brain. Oh the colors!";
const auto service_name = ServiceName::create(name_value).expect("");
const auto service_name = iox2_testing::generate_service_name();

auto node = NodeBuilder().create<SERVICE_TYPE>().expect("");
auto service = node.service_builder(service_name)
Expand All @@ -362,8 +347,7 @@ TYPED_TEST(ServicePublishSubscribeTest, open_fails_with_incompatible_subscriber_
TYPED_TEST(ServicePublishSubscribeTest, publisher_applies_unable_to_deliver_strategy) {
constexpr ServiceType SERVICE_TYPE = TestFixture::TYPE;

const auto* name_value = "I am floating through the galaxy of my brain. Oh the colors!";
const auto service_name = ServiceName::create(name_value).expect("");
const auto service_name = iox2_testing::generate_service_name();

auto node = NodeBuilder().create<SERVICE_TYPE>().expect("");
auto service = node.service_builder(service_name).template publish_subscribe<uint64_t>().create().expect("");
Expand All @@ -382,8 +366,7 @@ TYPED_TEST(ServicePublishSubscribeTest, publisher_applies_unable_to_deliver_stra
TYPED_TEST(ServicePublishSubscribeTest, send_receive_with_user_header_works) {
constexpr ServiceType SERVICE_TYPE = TestFixture::TYPE;

const auto* name_value = "I am floating through the galaxy of my brain. Oh the colors!";
const auto service_name = ServiceName::create(name_value).expect("");
const auto service_name = iox2_testing::generate_service_name();

auto node = NodeBuilder().create<SERVICE_TYPE>().expect("");
auto service_pub = node.service_builder(service_name)
Expand Down Expand Up @@ -420,8 +403,7 @@ TYPED_TEST(ServicePublishSubscribeTest, send_receive_with_user_header_works) {
TYPED_TEST(ServicePublishSubscribeTest, has_sample_works) {
constexpr ServiceType SERVICE_TYPE = TestFixture::TYPE;

const auto* name_value = "I am floating through the galaxy of my brain. Oh the colors!";
const auto service_name = ServiceName::create(name_value).expect("");
const auto service_name = iox2_testing::generate_service_name();

auto node = NodeBuilder().create<SERVICE_TYPE>().expect("");
auto service = node.service_builder(service_name).template publish_subscribe<uint64_t>().create().expect("");
Expand All @@ -437,6 +419,4 @@ TYPED_TEST(ServicePublishSubscribeTest, has_sample_works) {
auto sample = sut_subscriber.receive().expect("");
ASSERT_FALSE(*sut_subscriber.has_samples());
}


} // namespace
10 changes: 10 additions & 0 deletions iceoryx2-ffi/cxx/tests/src/test.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <gmock/gmock.h>
#include <gtest/gtest.h>

#include "iox2/service_name.hpp"
#include "iox2/service_type.hpp"

using namespace ::testing;
Expand All @@ -31,6 +32,15 @@ using ServiceTypeLocal = TypeServiceType<ServiceType::Local>;

using ServiceTypes = ::testing::Types<ServiceTypeIpc, ServiceTypeLocal>;

inline auto generate_service_name() -> ServiceName {
static std::atomic<uint64_t> COUNTER = 0;
uint64_t now = std::chrono::system_clock::now().time_since_epoch().count();
int random_number = rand(); // NOLINT(cert-msc30-c,cert-msc50-cpp)
return ServiceName::create((std::string("service_event_tests_") + std::to_string(COUNTER.fetch_add(1)) + "_"
+ std::to_string(now) + "_" + std::to_string(random_number))
.c_str())
.expect("");
}
} // namespace iox2_testing

#endif // IOX2_CXX_TESTS_TEST_HPP
8 changes: 1 addition & 7 deletions iceoryx2-ffi/cxx/tests/src/unique_port_id_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,13 @@
namespace {
using namespace iox2;

auto generate_name() -> ServiceName {
static std::atomic<uint64_t> COUNTER = 0;
return ServiceName::create((std::string("unique_port_id_tests_") + std::to_string(COUNTER.fetch_add(1))).c_str())
.expect("");
}

template <typename T>
struct UniquePortIdTest : public ::testing::Test {
static constexpr ServiceType TYPE = T::TYPE;

UniquePortIdTest()
: node { NodeBuilder().create<TYPE>().expect("") }
, service_name { generate_name() }
, service_name { iox2_testing::generate_service_name() }
, event { node.service_builder(service_name).event().create().expect("") }
, pubsub { node.service_builder(service_name).template publish_subscribe<uint64_t>().create().expect("") }
, listener_1 { event.listener_builder().create().expect("") }
Expand Down

0 comments on commit 3a8b0ee

Please sign in to comment.