Skip to content

Commit

Permalink
iox-eclipse-iceoryx#454 fix review findings
Browse files Browse the repository at this point in the history
Signed-off-by: Manel Melaouhi <[email protected]>
  • Loading branch information
manel94 authored and marthtz committed May 12, 2021
1 parent 3aa85d0 commit 0172e47
Showing 1 changed file with 27 additions and 31 deletions.
58 changes: 27 additions & 31 deletions iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (c) 2019, 2021 by Robert Bosch GmbH, Apex.AI Inc. All rights reserved.
// Copyright (c) 2019 - 2021 by Apex.AI Inc. All rights reserved.
// Copyright (c) 2021 by Robert Bosch GmbH. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -331,7 +332,7 @@ TEST_F(PortManager_test, AcquiringOneMoreThanMaximumNumberOfInterfacesFails)
}
}

TEST_F(PortManager_test, deleteInterfacePortfromMaximumNumberAndAddOneIsSuccessful)
TEST_F(PortManager_test, DeleteInterfacePortfromMaximumNumberAndAddOneIsSuccessful)
{
std::string itf = "itf";

Expand Down Expand Up @@ -382,7 +383,7 @@ TEST_F(PortManager_test, AcquiringOneMoreThanMaximumNumberOfApplicationsFails)
}
}

TEST_F(PortManager_test, deleteApplicationPortfromMaximumNumberAndAddOneIsSuccessful)
TEST_F(PortManager_test, DeleteApplicationPortfromMaximumNumberAndAddOneIsSuccessful)
{
std::string app = "app";

Expand Down Expand Up @@ -434,7 +435,7 @@ TEST_F(PortManager_test, AcquiringOneMoreThanMaximumNumberOfConditionVariablesFa
}
}

TEST_F(PortManager_test, deleteConditionVariablePortfromMaximumNumberAndAddOneIsSuccessful)
TEST_F(PortManager_test, DeleteConditionVariablePortfromMaximumNumberAndAddOneIsSuccessful)
{
std::string process = "HypnoToadForEver";

Expand Down Expand Up @@ -491,6 +492,22 @@ TEST_F(PortManager_test, AcquireConditionVariablesDataAfterDestroyingPreviouslyA
}
}

TEST_F(PortManager_test, AcquiringMaximumNumberOfNodesWorks)
{
std::string process = "Process";
std::string node = "Node";

for (unsigned int i = 0U; i < iox::MAX_NODE_NUMBER; i++)
{
iox::ProcessName_t newProcessName(iox::cxx::TruncateToCapacity, process + std::to_string(i));
iox::NodeName_t newNodeName(iox::cxx::TruncateToCapacity, node + std::to_string(i));
auto nodeData = m_portManager->acquireNodeData(newProcessName, newNodeName);
EXPECT_THAT(nodeData.has_error(), Eq(false));
EXPECT_THAT(nodeData.value()->m_node, StrEq(newNodeName));
EXPECT_THAT(nodeData.value()->m_process, StrEq(newProcessName));
}
}

TEST_F(PortManager_test, AcquiringOneMoreThanMaximumNumberOfNodesFails)
{
std::string process = "Process";
Expand All @@ -503,8 +520,6 @@ TEST_F(PortManager_test, AcquiringOneMoreThanMaximumNumberOfNodesFails)
iox::NodeName_t newNodeName(iox::cxx::TruncateToCapacity, node + std::to_string(i));
auto nodeData = m_portManager->acquireNodeData(newProcessName, newNodeName);
ASSERT_THAT(nodeData.has_error(), Eq(false));
EXPECT_THAT(nodeData.value()->m_node, StrEq(newNodeName));
EXPECT_THAT(nodeData.value()->m_process, StrEq(newProcessName));
}

// test if overflow errors get hit
Expand All @@ -520,7 +535,7 @@ TEST_F(PortManager_test, AcquiringOneMoreThanMaximumNumberOfNodesFails)
EXPECT_THAT(nodeData.get_error(), Eq(PortPoolError::NODE_DATA_LIST_FULL));
}

TEST_F(PortManager_test, deleteNodePortfromMaximumNumberandAddOneIsSuccessful)
TEST_F(PortManager_test, DeleteNodePortfromMaximumNumberandAddOneIsSuccessful)
{
std::string process = "Process";
std::string node = "Node";
Expand Down Expand Up @@ -577,7 +592,7 @@ TEST_F(PortManager_test, AcquireNodeDataAfterDestroyingPreviouslyAcquiredOnesIsS
}
}

TEST_F(PortManager_test, DestroyPortsInProcessP2ChangesStatesOfPortsInProcessP1)
TEST_F(PortManager_test, PortsDestroyInP2ChangeStatesOfPortsInProcessP1)
{
iox::ProcessName_t p1 = "myProcess1";
iox::ProcessName_t p2 = "myProcess2";
Expand Down Expand Up @@ -645,38 +660,19 @@ TEST_F(PortManager_test, DestroyPortsInProcessP2ChangesStatesOfPortsInProcessP1)
EXPECT_THAT(subscriber1.getSubscriptionState(), Eq(iox::SubscribeState::WAIT_FOR_OFFER));
}
}
}

TEST_F(PortManager_test, CleanupProcessP2ChangesStatesOfPortsInProcessP1)
{
iox::ProcessName_t p1 = "myProcess1";
iox::ProcessName_t p2 = "myProcess2";
iox::capro::ServiceDescription cap1(1, 1, 1);
iox::capro::ServiceDescription cap2(2, 2, 2);
PublisherOptions publisherOptions{1, "node"};
SubscriberOptions subscriberOptions{1, 1, "node"};

// two processes p1 and p2 each with a publisher and subscriber that match to the other process
auto publisherData1 =
m_portManager->acquirePublisherPortData(cap1, publisherOptions, p1, m_payloadMemoryManager, PortConfigInfo())
.value();
auto subscriberData1 =
m_portManager->acquireSubscriberPortData(cap2, subscriberOptions, p1, PortConfigInfo()).value();

auto publisherData2 =
// re-create the ports of process p2
publisherData2 =
m_portManager->acquirePublisherPortData(cap2, publisherOptions, p2, m_payloadMemoryManager, PortConfigInfo())
.value();
auto subscriberData2 =
m_portManager->acquireSubscriberPortData(cap1, subscriberOptions, p2, PortConfigInfo()).value();
subscriberData2 = m_portManager->acquireSubscriberPortData(cap1, subscriberOptions, p2, PortConfigInfo()).value();

// let them connect
{
PublisherPortUser publisher1(publisherData1);
ASSERT_TRUE(publisher1);
publisher1.offer();
SubscriberPortUser subscriber1(subscriberData1);
ASSERT_TRUE(subscriber1);
subscriber1.subscribe();

PublisherPortUser publisher2(publisherData2);
ASSERT_TRUE(publisher2);
Expand Down Expand Up @@ -756,5 +752,5 @@ TEST_F(PortManager_test, OfferPublisherServiceUpdatesServiceRegistryChangeCounte
publisher.offer();
m_portManager->doDiscovery();

EXPECT_EQ(initialCount + 1 == serviceCounter->load(), true);
EXPECT_EQ(serviceCounter->load(), initialCount + 1);
}

0 comments on commit 0172e47

Please sign in to comment.