Skip to content

Commit

Permalink
Refs #20256: Apply changes to ExtendedIncompatibleQos samples
Browse files Browse the repository at this point in the history
Signed-off-by: Carlosespicur <[email protected]>
  • Loading branch information
Carlosespicur committed Dec 10, 2024
1 parent 60d5663 commit 7bf1ab4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
18 changes: 18 additions & 0 deletions src/cpp/database/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2126,6 +2126,15 @@ bool Database::insert_nts(
std::shared_ptr<const DataReader> const_datareader = std::dynamic_pointer_cast<const DataReader>(
entity);
std::shared_ptr<DataReader> datareader = std::const_pointer_cast<DataReader>(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>(datareader);
break;
Expand All @@ -2135,6 +2144,15 @@ bool Database::insert_nts(
std::shared_ptr<const DataWriter> const_datawriter = std::dynamic_pointer_cast<const DataWriter>(
entity);
std::shared_ptr<DataWriter> datawriter = std::const_pointer_cast<DataWriter>(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>(datawriter);
break;
Expand Down
11 changes: 10 additions & 1 deletion test/unittest/Database/DatabaseTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint32_t>{1, 2});
sample_2.extended_incompatible_qos_status = {status};
ASSERT_NO_THROW(db.insert(domain_id, writer_id, sample_2));
Expand All @@ -3122,6 +3122,15 @@ TEST_F(database_tests, insert_monitor_service_sample_extended_incompatible_qos)
static_cast<ExtendedIncompatibleQosSample>(sample));
ASSERT_EQ(writer->monitor_service_data.extended_incompatible_qos[1],
static_cast<ExtendedIncompatibleQosSample>(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<ExtendedIncompatibleQosSample>(sample));
ASSERT_EQ(writer->monitor_service_data.extended_incompatible_qos[1],
static_cast<ExtendedIncompatibleQosSample>(sample_2));
}

TEST_F(database_tests, insert_monitor_service_sample_extended_incompatible_qos_wrong_entity)
Expand Down

0 comments on commit 7bf1ab4

Please sign in to comment.