From 7bf1ab4b3acb35205bdd87eee8063e0ad4c1377b Mon Sep 17 00:00:00 2001 From: Carlosespicur Date: Tue, 10 Dec 2024 10:28:32 +0100 Subject: [PATCH] Refs #20256: Apply changes to ExtendedIncompatibleQos samples Signed-off-by: Carlosespicur --- src/cpp/database/database.cpp | 18 ++++++++++++++++++ test/unittest/Database/DatabaseTests.cpp | 11 ++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/cpp/database/database.cpp b/src/cpp/database/database.cpp index e48f574f..69375ae8 100644 --- a/src/cpp/database/database.cpp +++ b/src/cpp/database/database.cpp @@ -2126,6 +2126,15 @@ bool Database::insert_nts( std::shared_ptr const_datareader = std::dynamic_pointer_cast( entity); std::shared_ptr datareader = std::const_pointer_cast(const_datareader); + + // Reject samples with old timestamps + if (!datareader->monitor_service_data.extended_incompatible_qos.empty() && + extended_incompatible_qos.src_ts <= + datareader->monitor_service_data.extended_incompatible_qos.back().src_ts) + { + break; + } + datareader->monitor_service_data.extended_incompatible_qos.push_back(extended_incompatible_qos); entity_updated = update_entity_status_nts(datareader); break; @@ -2135,6 +2144,15 @@ bool Database::insert_nts( std::shared_ptr const_datawriter = std::dynamic_pointer_cast( entity); std::shared_ptr datawriter = std::const_pointer_cast(const_datawriter); + + // Reject samples with old timestamps + if (!datawriter->monitor_service_data.extended_incompatible_qos.empty() && + extended_incompatible_qos.src_ts <= + datawriter->monitor_service_data.extended_incompatible_qos.back().src_ts) + { + break; + } + datawriter->monitor_service_data.extended_incompatible_qos.push_back(extended_incompatible_qos); entity_updated = update_entity_status_nts(datawriter); break; diff --git a/test/unittest/Database/DatabaseTests.cpp b/test/unittest/Database/DatabaseTests.cpp index fda40b0a..0909697b 100644 --- a/test/unittest/Database/DatabaseTests.cpp +++ b/test/unittest/Database/DatabaseTests.cpp @@ -3108,7 +3108,7 @@ TEST_F(database_tests, insert_monitor_service_sample_extended_incompatible_qos) ExtendedIncompatibleQosSample sample_2; sample_2.kind = StatusKind::EXTENDED_INCOMPATIBLE_QOS; sample_2.status = StatusLevel::ERROR_STATUS; - sample_2.src_ts = std::chrono::system_clock::now(); + sample_2.src_ts = std::chrono::system_clock::now() + std::chrono::seconds(1); status.current_incompatible_policies(std::vector{1, 2}); sample_2.extended_incompatible_qos_status = {status}; ASSERT_NO_THROW(db.insert(domain_id, writer_id, sample_2)); @@ -3122,6 +3122,15 @@ TEST_F(database_tests, insert_monitor_service_sample_extended_incompatible_qos) static_cast(sample)); ASSERT_EQ(writer->monitor_service_data.extended_incompatible_qos[1], static_cast(sample_2)); + + // Insert old sample - should not be inserted + ASSERT_NO_THROW(db.insert(domain_id, writer_id, sample_2)); + ASSERT_EQ(writer->monitor_service_data.extended_incompatible_qos.size(), 2u); + ASSERT_EQ(reader->monitor_service_data.extended_incompatible_qos.size(), 1u); + ASSERT_EQ(writer->monitor_service_data.extended_incompatible_qos[0], + static_cast(sample)); + ASSERT_EQ(writer->monitor_service_data.extended_incompatible_qos[1], + static_cast(sample_2)); } TEST_F(database_tests, insert_monitor_service_sample_extended_incompatible_qos_wrong_entity)