Skip to content

Commit

Permalink
Refs 6233. Improve liveliness tests
Browse files Browse the repository at this point in the history
This is a port of #982 + #983 + #985 from 1.9.x
  • Loading branch information
IkerLuengo committed Feb 25, 2020
1 parent f780159 commit 227b8ce
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 4 deletions.
57 changes: 56 additions & 1 deletion test/blackbox/BlackboxTestsLivelinessQos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,19 @@ class LivelinessQos : public testing::TestWithParam<bool>
}
}

template<typename WriterType, typename ReaderType>
void config_pdp(
WriterType& writer,
ReaderType& reader)
{
constexpr unsigned int participant_announcement_period_ms = 50000;

writer.lease_duration(
participant_announcement_period_ms * 3e-3, participant_announcement_period_ms * 1e-3);
reader.lease_duration(
participant_announcement_period_ms * 3e-3, participant_announcement_period_ms * 1e-3);
}

};

//! Tests that when kind is automatic liveliness is never lost, even if the writer never sends data
Expand All @@ -59,6 +72,8 @@ TEST_P(LivelinessQos, Liveliness_Automatic_Reliable)
PubSubReader<HelloWorldType> reader(TEST_TOPIC_NAME);
PubSubWriter<HelloWorldType> writer(TEST_TOPIC_NAME);

config_pdp(writer, reader);

// Liveliness lease duration and announcement period
unsigned int lease_duration_ms = 1000;
unsigned int announcement_period_ms = 1;
Expand Down Expand Up @@ -95,6 +110,8 @@ TEST_P(LivelinessQos, Liveliness_Automatic_BestEffort)
PubSubReader<HelloWorldType> reader(TEST_TOPIC_NAME);
PubSubWriter<HelloWorldType> writer(TEST_TOPIC_NAME);

config_pdp(writer, reader);

// Liveliness lease duration and announcement period
unsigned int lease_duration_ms = 1000;
unsigned int announcement_period_ms = 1;
Expand Down Expand Up @@ -133,6 +150,8 @@ TEST_P(LivelinessQos, ShortLiveliness_ManualByParticipant_Reliable)
PubSubReader<HelloWorldType> reader(TEST_TOPIC_NAME);
PubSubWriter<HelloWorldType> writer(TEST_TOPIC_NAME);

config_pdp(writer, reader);

// Number of samples to write
unsigned int num_samples = 2;

Expand Down Expand Up @@ -195,6 +214,8 @@ TEST_P(LivelinessQos, ShortLiveliness_ManualByParticipant_BestEffort)
PubSubReader<HelloWorldType> reader(TEST_TOPIC_NAME);
PubSubWriter<HelloWorldType> writer(TEST_TOPIC_NAME);

config_pdp(writer, reader);

// Number of samples to write
unsigned int num_samples = 2;

Expand Down Expand Up @@ -257,6 +278,8 @@ TEST_P(LivelinessQos, LongLiveliness_ManualByParticipant_Reliable)
PubSubReader<HelloWorldType> reader(TEST_TOPIC_NAME);
PubSubWriter<HelloWorldType> writer(TEST_TOPIC_NAME);

config_pdp(writer, reader);

// Number of samples to write
unsigned int num_samples = 2;

Expand Down Expand Up @@ -314,6 +337,8 @@ TEST_P(LivelinessQos, LongLiveliness_ManualByParticipant_BestEffort)
PubSubReader<HelloWorldType> reader(TEST_TOPIC_NAME);
PubSubWriter<HelloWorldType> writer(TEST_TOPIC_NAME);

config_pdp(writer, reader);

// Number of samples to write
unsigned int num_samples = 2;

Expand Down Expand Up @@ -371,6 +396,8 @@ TEST_P(LivelinessQos, ShortLiveliness_ManualByTopic_Reliable)
PubSubReader<HelloWorldType> reader(TEST_TOPIC_NAME);
PubSubWriter<HelloWorldType> writer(TEST_TOPIC_NAME);

config_pdp(writer, reader);

// Number of samples to write
unsigned int num_samples = 2;

Expand Down Expand Up @@ -431,6 +458,8 @@ TEST_P(LivelinessQos, ShortLiveliness_ManualByTopic_BestEffort)
PubSubReader<HelloWorldType> reader(TEST_TOPIC_NAME);
PubSubWriter<HelloWorldType> writer(TEST_TOPIC_NAME);

config_pdp(writer, reader);

// Number of samples to write
unsigned int num_samples = 2;

Expand Down Expand Up @@ -491,6 +520,8 @@ TEST_P(LivelinessQos, LongLiveliness_ManualByTopic_Reliable)
PubSubReader<HelloWorldType> reader(TEST_TOPIC_NAME);
PubSubWriter<HelloWorldType> writer(TEST_TOPIC_NAME);

config_pdp(writer, reader);

// Number of samples to write
unsigned int num_samples = 2;

Expand Down Expand Up @@ -548,6 +579,8 @@ TEST_P(LivelinessQos, LongLiveliness_ManualByTopic_BestEffort)
PubSubReader<HelloWorldType> reader(TEST_TOPIC_NAME);
PubSubWriter<HelloWorldType> writer(TEST_TOPIC_NAME);

config_pdp(writer, reader);

// Number of samples to write
unsigned int num_samples = 2;

Expand Down Expand Up @@ -605,6 +638,8 @@ TEST_P(LivelinessQos, LongLiveliness_ManualByParticipant_Automatic_Reliable)
PubSubReader<HelloWorldType> reader(TEST_TOPIC_NAME);
PubSubWriter<HelloWorldType> writer(TEST_TOPIC_NAME);

config_pdp(writer, reader);

// Write rate in milliseconds and number of samples to write
unsigned int num_samples = 2;

Expand Down Expand Up @@ -661,6 +696,8 @@ TEST_P(LivelinessQos, ShortLiveliness_ManualByParticipant_Automatic_Reliable)
PubSubReader<HelloWorldType> reader(TEST_TOPIC_NAME);
PubSubWriter<HelloWorldType> writer(TEST_TOPIC_NAME);

config_pdp(writer, reader);

// Number of samples to write
unsigned int num_samples = 2;

Expand Down Expand Up @@ -721,6 +758,8 @@ TEST_P(LivelinessQos, LongLiveliness_ManualByParticipant_Automatic_BestEffort)
PubSubReader<HelloWorldType> reader(TEST_TOPIC_NAME);
PubSubWriter<HelloWorldType> writer(TEST_TOPIC_NAME);

config_pdp(writer, reader);

// Number of samples to write
unsigned int num_samples = 2;

Expand Down Expand Up @@ -778,6 +817,8 @@ TEST_P(LivelinessQos, ShortLiveliness_ManualByParticipant_Automatic_BestEffort)
PubSubReader<HelloWorldType> reader(TEST_TOPIC_NAME);
PubSubWriter<HelloWorldType> writer(TEST_TOPIC_NAME);

config_pdp(writer, reader);

// Number of samples to write
unsigned int num_samples = 2;

Expand Down Expand Up @@ -838,6 +879,8 @@ TEST_P(LivelinessQos, ShortLiveliness_ManualByTopic_Automatic_Reliable)
PubSubReader<HelloWorldType> reader(TEST_TOPIC_NAME);
PubSubWriter<HelloWorldType> writer(TEST_TOPIC_NAME);

config_pdp(writer, reader);

// Number of samples to write
unsigned int num_samples = 2;

Expand Down Expand Up @@ -897,6 +940,8 @@ TEST_P(LivelinessQos, ShortLiveliness_ManualByTopic_Automatic_BestEffort)
PubSubReader<HelloWorldType> reader(TEST_TOPIC_NAME);
PubSubWriter<HelloWorldType> writer(TEST_TOPIC_NAME);

config_pdp(writer, reader);

// Number of times to assert liveliness
unsigned int num_samples = 2;

Expand Down Expand Up @@ -956,6 +1001,8 @@ TEST_P(LivelinessQos, ShortLiveliness_ManualByTopic_ManualByParticipant_Reliable
PubSubReader<HelloWorldType> reader(TEST_TOPIC_NAME);
PubSubWriter<HelloWorldType> writer(TEST_TOPIC_NAME);

config_pdp(writer, reader);

// Number of samples to write
unsigned int num_samples = 2;

Expand Down Expand Up @@ -1015,6 +1062,8 @@ TEST_P(LivelinessQos, ShortLiveliness_ManualByTopic_ManualByParticipant_BestEffo
PubSubReader<HelloWorldType> reader(TEST_TOPIC_NAME);
PubSubWriter<HelloWorldType> writer(TEST_TOPIC_NAME);

config_pdp(writer, reader);

// Write rate in milliseconds and number of samples to write
unsigned int num_samples = 2;

Expand Down Expand Up @@ -1056,7 +1105,7 @@ TEST_P(LivelinessQos, ShortLiveliness_ManualByTopic_ManualByParticipant_BestEffo
for (count = 0; count < num_samples; count++)
{
writer.assert_liveliness();
std::this_thread::sleep_for(std::chrono::milliseconds(lease_duration_ms * 2));
writer.wait_liveliness_lost(num_samples + count + 1);
}

EXPECT_EQ(writer.times_liveliness_lost(), num_samples * 2);
Expand Down Expand Up @@ -1417,6 +1466,8 @@ TEST_P(LivelinessQos, LivelinessChangedStatus_Alive_NotAlive)
PubSubReader<HelloWorldType> reader(TEST_TOPIC_NAME);
PubSubWriter<HelloWorldType> writer(TEST_TOPIC_NAME);

config_pdp(writer, reader);

// Liveliness lease duration and announcement period, in milliseconds
unsigned int lease_duration_ms = 100;
unsigned int announcement_period_ms = 10;
Expand Down Expand Up @@ -1472,6 +1523,8 @@ TEST_P(LivelinessQos, LivelinessChangedStatus_Alive_Unmatched)
PubSubReader<HelloWorldType> reader(TEST_TOPIC_NAME);
PubSubWriter<HelloWorldType> writer(TEST_TOPIC_NAME);

config_pdp(writer, reader);

// Liveliness lease duration and announcement period, in milliseconds
unsigned int lease_duration_ms = 100;
unsigned int announcement_period_ms = 10;
Expand Down Expand Up @@ -1523,6 +1576,8 @@ TEST_P(LivelinessQos, LivelinessChangedStatus_NotAlive_Unmatched)
PubSubReader<HelloWorldType> reader(TEST_TOPIC_NAME);
PubSubWriter<HelloWorldType> writer(TEST_TOPIC_NAME);

config_pdp(writer, reader);

// Liveliness lease duration and announcement period, in milliseconds
unsigned int lease_duration_ms = 100;
unsigned int announcement_period_ms = 10;
Expand Down
6 changes: 3 additions & 3 deletions test/blackbox/PubSubParticipant.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,19 +281,19 @@ class PubSubParticipant
void pub_wait_liveliness_lost(unsigned int times = 1)
{
std::unique_lock<std::mutex> lock(pub_liveliness_mutex_);
pub_liveliness_cv_.wait(lock, [&]() { return pub_times_liveliness_lost_ == times; });
pub_liveliness_cv_.wait(lock, [&]() { return pub_times_liveliness_lost_ >= times; });
}

void sub_wait_liveliness_recovered(unsigned int num_recovered)
{
std::unique_lock<std::mutex> lock(sub_liveliness_mutex_);
sub_liveliness_cv_.wait(lock, [&]() { return sub_times_liveliness_recovered_ == num_recovered; });
sub_liveliness_cv_.wait(lock, [&]() { return sub_times_liveliness_recovered_ >= num_recovered; });
}

void sub_wait_liveliness_lost(unsigned int num_lost)
{
std::unique_lock<std::mutex> lock(sub_liveliness_mutex_);
sub_liveliness_cv_.wait(lock, [&]() { return sub_times_liveliness_lost_ == num_lost; });
sub_liveliness_cv_.wait(lock, [&]() { return sub_times_liveliness_lost_ >= num_lost; });
}

PubSubParticipant& pub_topic_name(std::string topicName)
Expand Down

0 comments on commit 227b8ce

Please sign in to comment.