Skip to content

Commit

Permalink
Refs #20739: Refactor tests
Browse files Browse the repository at this point in the history
Signed-off-by: Mario Dominguez <[email protected]>
  • Loading branch information
Mario-DL committed Apr 4, 2024
1 parent 33ce4ba commit fd4005b
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,18 @@

#include <gmock/gmock.h>

#ifdef FASTDDS_STATISTICS
#include <fastdds/statistics/rtps/monitor_service/interfaces/IProxyObserver.hpp>
#endif // ifdef FASTDDS_STATISTICS

namespace eprosima {

namespace fastdds {
namespace statistics {
namespace rtps {

struct IProxyObserver;

} // namespace rtps
} // namespace statistics
} // namespace fastdds

namespace fastrtps {
namespace rtps {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@
#include <fastdds/rtps/common/Guid.h>
#include <fastdds/rtps/reader/StatefulReader.h>
#include <fastdds/rtps/resources/ResourceEvent.h>
#include <fastdds/statistics/rtps/monitor_service/Interfaces.hpp>
#include <fastrtps/fastrtps_dll.h>
#include <fastrtps/qos/ReaderQos.h>
#include <fastrtps/qos/WriterQos.h>

#include <gmock/gmock.h>

#include <statistics/rtps/monitor-service/Interfaces.hpp>

namespace eprosima {

namespace fastdds {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,9 @@ class DomainParticipantImplTest : public DomainParticipantImpl

bool monitoring_status(
fastrtps::rtps::GUID_t guid,
uint32_t status_id,
fastdds::statistics::rtps::DDSEntityStatus*& status)
statistics::MonitorServiceData& status)
{
return get_monitoring_status(guid, status_id, status);
return get_monitoring_status(guid, status);
}

};
Expand Down Expand Up @@ -188,17 +187,20 @@ TEST_F(StatisticsDomainParticipantStatusQueryableTests, istatus_queryable_get_in
statistics_pub_impl->insert_policy_violation(dw1->guid(), fastdds::dds::RELIABILITY_QOS_POLICY_ID);
statistics_pub_impl->insert_policy_violation(dw2->guid(), fastdds::dds::RELIABILITY_QOS_POLICY_ID);

fastdds::statistics::rtps::DDSEntityStatus* incomp_qos_status_dw_1, * incomp_qos_status_dw_2;
incomp_qos_status_dw_1 = new fastdds::statistics::rtps::DDSEntityStatus;
incomp_qos_status_dw_2 = new fastdds::statistics::rtps::DDSEntityStatus;
ASSERT_TRUE(statistics_participant_impl_test->monitoring_status(dw1->guid(), 2, incomp_qos_status_dw_1));
ASSERT_TRUE(statistics_participant_impl_test->monitoring_status(dw2->guid(), 2, incomp_qos_status_dw_2));
MonitorServiceData incomp_qos_status_dw_1;
incomp_qos_status_dw_1.incompatible_qos_status(IncompatibleQoSStatus_s{});
MonitorServiceData incomp_qos_status_dw_2;
incomp_qos_status_dw_2.incompatible_qos_status(IncompatibleQoSStatus_s{});
ASSERT_TRUE(statistics_participant_impl_test->monitoring_status(dw1->guid(), incomp_qos_status_dw_1));
ASSERT_TRUE(statistics_participant_impl_test->monitoring_status(dw2->guid(), incomp_qos_status_dw_2));

//! Expect incompatibilities
ASSERT_EQ(1u, static_cast<fastdds::dds::IncompatibleQosStatus*>(incomp_qos_status_dw_1)->total_count);
ASSERT_EQ(1u, static_cast<fastdds::dds::IncompatibleQosStatus*>(incomp_qos_status_dw_2)->total_count);
ASSERT_EQ(1u, incomp_qos_status_dw_1->policies[fastdds::dds::RELIABILITY_QOS_POLICY_ID].count);
ASSERT_EQ(1u, incomp_qos_status_dw_2->policies[fastdds::dds::RELIABILITY_QOS_POLICY_ID].count);
ASSERT_EQ(1u, incomp_qos_status_dw_1.incompatible_qos_status().total_count());
ASSERT_EQ(1u, incomp_qos_status_dw_2.incompatible_qos_status().total_count());
ASSERT_EQ(1u,
incomp_qos_status_dw_1.incompatible_qos_status().policies()[fastdds::dds::RELIABILITY_QOS_POLICY_ID].count());
ASSERT_EQ(1u,
incomp_qos_status_dw_2.incompatible_qos_status().policies()[fastdds::dds::RELIABILITY_QOS_POLICY_ID].count());

statistics_pub_impl->delete_datawriters();
topic->get_impl()->dereference();
Expand All @@ -207,9 +209,6 @@ TEST_F(StatisticsDomainParticipantStatusQueryableTests, istatus_queryable_get_in
statistics_participant->delete_publisher(publisher);
statistics_participant->delete_contained_entities();

delete incomp_qos_status_dw_1;
delete incomp_qos_status_dw_2;

#endif // FASTDDS_STATISTICS
}

Expand Down Expand Up @@ -251,15 +250,16 @@ TEST_F(StatisticsDomainParticipantStatusQueryableTests, istatus_queryable_get_li
statistics_pub_impl->insert_policy_violation(dw1->guid(), fastdds::dds::LIVELINESS_QOS_POLICY_ID);
statistics_pub_impl->insert_policy_violation(dw2->guid(), fastdds::dds::LIVELINESS_QOS_POLICY_ID);

rtps::DDSEntityStatus* liv_lost_status_dw_1, * liv_lost_status_dw_2;
liv_lost_status_dw_1 = new fastdds::statistics::rtps::DDSEntityStatus;
liv_lost_status_dw_2 = new fastdds::statistics::rtps::DDSEntityStatus;
ASSERT_TRUE(statistics_participant_impl_test->monitoring_status(dw1->guid(), 4, liv_lost_status_dw_1));
ASSERT_TRUE(statistics_participant_impl_test->monitoring_status(dw2->guid(), 4, liv_lost_status_dw_2));
MonitorServiceData liv_lost_status_dw_1;
liv_lost_status_dw_1.liveliness_lost_status(LivelinessLostStatus_s{});
MonitorServiceData liv_lost_status_dw_2;
liv_lost_status_dw_2.liveliness_lost_status(LivelinessLostStatus_s{});
ASSERT_TRUE(statistics_participant_impl_test->monitoring_status(dw1->guid(), liv_lost_status_dw_1));
ASSERT_TRUE(statistics_participant_impl_test->monitoring_status(dw2->guid(), liv_lost_status_dw_2));

//! Expect incompatibilities
ASSERT_EQ(1, static_cast<fastdds::dds::LivelinessLostStatus*>(liv_lost_status_dw_1)->total_count);
ASSERT_EQ(1, static_cast<fastdds::dds::LivelinessLostStatus*>(liv_lost_status_dw_2)->total_count);
ASSERT_EQ(1u, liv_lost_status_dw_1.liveliness_lost_status().total_count());
ASSERT_EQ(1u, liv_lost_status_dw_2.liveliness_lost_status().total_count());

statistics_pub_impl->delete_datawriters();
topic->get_impl()->dereference();
Expand All @@ -268,9 +268,6 @@ TEST_F(StatisticsDomainParticipantStatusQueryableTests, istatus_queryable_get_li
statistics_participant->delete_publisher(publisher);
statistics_participant->delete_contained_entities();

delete liv_lost_status_dw_1;
delete liv_lost_status_dw_2;

#endif // FASTDDS_STATISTICS
}

Expand Down Expand Up @@ -312,15 +309,16 @@ TEST_F(StatisticsDomainParticipantStatusQueryableTests, istatus_queryable_get_de
statistics_pub_impl->insert_policy_violation(dw1->guid(), fastdds::dds::DEADLINE_QOS_POLICY_ID);
statistics_pub_impl->insert_policy_violation(dw2->guid(), fastdds::dds::DEADLINE_QOS_POLICY_ID);

rtps::DDSEntityStatus* deadline_missed_status_dw_1, * deadline_missed_status_dw_2;
deadline_missed_status_dw_1 = new rtps::DDSEntityStatus;
deadline_missed_status_dw_2 = new rtps::DDSEntityStatus;
ASSERT_TRUE(statistics_participant_impl_test->monitoring_status(dw1->guid(), 6, deadline_missed_status_dw_1));
ASSERT_TRUE(statistics_participant_impl_test->monitoring_status(dw2->guid(), 6, deadline_missed_status_dw_2));
MonitorServiceData deadline_missed_status_dw_1;
deadline_missed_status_dw_1.deadline_missed_status(DeadlineMissedStatus_s{});
MonitorServiceData deadline_missed_status_dw_2;
deadline_missed_status_dw_2.deadline_missed_status(DeadlineMissedStatus_s{});
ASSERT_TRUE(statistics_participant_impl_test->monitoring_status(dw1->guid(), deadline_missed_status_dw_1));
ASSERT_TRUE(statistics_participant_impl_test->monitoring_status(dw2->guid(), deadline_missed_status_dw_2));

//! Expect incompatibilities
ASSERT_EQ(1u, static_cast<fastdds::dds::DeadlineMissedStatus*>(deadline_missed_status_dw_1)->total_count);
ASSERT_EQ(1u, static_cast<fastdds::dds::DeadlineMissedStatus*>(deadline_missed_status_dw_2)->total_count);
ASSERT_EQ(1u, deadline_missed_status_dw_1.deadline_missed_status().total_count());
ASSERT_EQ(1u, deadline_missed_status_dw_2.deadline_missed_status().total_count());

statistics_pub_impl->delete_datawriters();
topic->get_impl()->dereference();
Expand All @@ -329,9 +327,6 @@ TEST_F(StatisticsDomainParticipantStatusQueryableTests, istatus_queryable_get_de
statistics_participant->delete_publisher(publisher);
statistics_participant->delete_contained_entities();

delete deadline_missed_status_dw_1;
delete deadline_missed_status_dw_2;

#endif // FASTDDS_STATISTICS
}

Expand Down
15 changes: 7 additions & 8 deletions test/unittest/statistics/rtps/MonitorServiceTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

#include <fastdds/dds/log/Log.hpp>
#include <fastdds/rtps/resources/ResourceEvent.h>
#include <fastdds/statistics/rtps/monitor_service/Interfaces.hpp>

#include <statistics/rtps/monitor-service/Interfaces.hpp>
#include <statistics/rtps/monitor-service/MonitorService.hpp>
#include <statistics/rtps/monitor-service/MonitorServiceListener.hpp>

Expand All @@ -30,10 +30,9 @@ namespace rtps {

struct MockStatusQueryable : public IStatusQueryable
{
MOCK_METHOD3(get_monitoring_status, bool (
MOCK_METHOD2(get_monitoring_status, bool (
const fastrtps::rtps::GUID_t& guid,
const uint32_t& id,
DDSEntityStatus * &status));
MonitorServiceData & status));
};

struct MockConnectionsQueryable : public IConnectionsQueryable
Expand Down Expand Up @@ -208,11 +207,11 @@ TEST_F(MonitorServiceTests, multiple_dds_status_updates)
ASSERT_TRUE(monitor_srv_.enable_monitor_service());
ASSERT_TRUE(monitor_srv_.is_enabled());

ON_CALL(mock_status_q_, get_monitoring_status(::testing::_, ::testing::_, ::testing::_)).
ON_CALL(mock_status_q_, get_monitoring_status(::testing::_, ::testing::_)).
WillByDefault(testing::Return(true));

//! Expect the getters for each status that is going to be updated
EXPECT_CALL(mock_status_q_, get_monitoring_status(::testing::_, ::testing::_, ::testing::_)).
EXPECT_CALL(mock_status_q_, get_monitoring_status(::testing::_, ::testing::_)).
Times(n_local_entities * 5);//statuses * n_local_entities

//! Trigger statuses updates for each entity
Expand Down Expand Up @@ -247,7 +246,7 @@ TEST_F(MonitorServiceTests, entity_removal_correctly_performs)
WillByDefault(testing::Return(true));
ON_CALL(mock_conns_q_, get_entity_connections(::testing::_, ::testing::_)).
WillByDefault(testing::Return(true));
ON_CALL(mock_status_q_, get_monitoring_status(::testing::_, ::testing::_, ::testing::_)).
ON_CALL(mock_status_q_, get_monitoring_status(::testing::_, ::testing::_)).
WillByDefault(testing::Return(true));

//! Expect the creation 5 ones
Expand All @@ -257,7 +256,7 @@ TEST_F(MonitorServiceTests, entity_removal_correctly_performs)
Times(5);

//! Expect the getters for each status that is going to be updated
EXPECT_CALL(mock_status_q_, get_monitoring_status(::testing::_, ::testing::_, ::testing::_)).
EXPECT_CALL(mock_status_q_, get_monitoring_status(::testing::_, ::testing::_)).
Times(5 * 5);

//! Trigger statuses updates for each of the non-existent entity
Expand Down
2 changes: 1 addition & 1 deletion test/unittest/statistics/rtps/RTPSStatisticsTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
#include <fastdds/rtps/RTPSDomain.h>
#include <fastdds/rtps/writer/RTPSWriter.h>
#include <fastdds/statistics/IListeners.hpp>
#include <fastdds/statistics/rtps/monitor_service/Interfaces.hpp>
#include <fastrtps/attributes/LibrarySettingsAttributes.h>
#include <fastrtps/attributes/LibrarySettingsAttributes.h>
#include <fastrtps/attributes/TopicAttributes.h>
Expand All @@ -52,6 +51,7 @@

#include <rtps/participant/RTPSParticipantImpl.h>
#include <rtps/transport/test_UDPv4Transport.h>
#include <statistics/rtps/monitor-service/Interfaces.hpp>
#include <statistics/types/types.h>
#include <utils/SystemInfo.hpp>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
#include <fastdds/rtps/history/WriterHistory.h>
#include <fastdds/rtps/resources/TimedEvent.h>
#include <fastdds/rtps/writer/StatefulWriter.h>
#include <fastdds/statistics/rtps/monitor_service/Interfaces.hpp>
#include <fastrtps/qos/WriterQos.h>

#include <rtps/history/ITopicPayloadPool.h>
#include <statistics/rtps/monitor-service/Interfaces.hpp>
#include <statistics/rtps/monitor-service/MonitorServiceListener.hpp>
#include <statistics/types/monitorservice_types.h>
#include <statistics/types/monitorservice_typesPubSubTypes.h>
Expand Down

0 comments on commit fd4005b

Please sign in to comment.