Skip to content

Commit

Permalink
Making liveliness tests more stable on Windows [5872] (eProsima#587)
Browse files Browse the repository at this point in the history
* Refs #5872 Changing some parameteres in the tests

* Refs #5872 Using condition variables in some tests that still fail on Ubuntu with valgrind

* Refs #5872 Also fixing LongLifespan test that failed on Linux

* Refs #5872 Changing more parameters to fix valgrind tests

* Refs #5872 Addressing review comments

* Refs #5872 Increasing some parameters even more
  • Loading branch information
raquelalvarezbanos authored and richiware committed Jul 11, 2019
1 parent 8505c53 commit eb2d1e7
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 58 deletions.
2 changes: 1 addition & 1 deletion test/blackbox/BlackboxTestsLifespanQoS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ TEST(LifespanQos, LongLifespan)
// Number of samples written by writer
uint32_t writer_samples = 3;
// Lifespan period in seconds
eprosima::fastrtps::Duration_t lifespan_s(writer_sleep_ms * 1000 * 1e-3);
eprosima::fastrtps::Duration_t lifespan_s(writer_sleep_ms * 1e4 * 1e-3);

writer.history_kind(eprosima::fastrtps::KEEP_ALL_HISTORY_QOS);
writer.lifespan_period(lifespan_s);
Expand Down
110 changes: 57 additions & 53 deletions test/blackbox/BlackboxTestsLivelinessQos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ TEST(LivelinessQos, Liveliness_Automatic_Reliable)
// Liveliness lease duration and announcement period
uint32_t liveliness_ms = 200;
Duration_t liveliness_s(liveliness_ms * 1e-3);
Duration_t announcement_period(liveliness_ms * 1e-3 * 0.5);
Duration_t announcement_period(liveliness_ms * 1e-3 * 0.01);

reader.reliability(RELIABLE_RELIABILITY_QOS)
.liveliness_kind(AUTOMATIC_LIVELINESS_QOS)
Expand Down Expand Up @@ -69,7 +69,7 @@ TEST(LivelinessQos, Liveliness_Automatic_BestEffort)
// Liveliness lease duration and announcement period
uint32_t liveliness_ms = 200;
Duration_t liveliness_s(liveliness_ms * 1e-3);
Duration_t announcement_period(liveliness_ms * 1e-3 * 0.5);
Duration_t announcement_period(liveliness_ms * 1e-3 * 0.01);

reader.reliability(BEST_EFFORT_RELIABILITY_QOS)
.liveliness_kind(AUTOMATIC_LIVELINESS_QOS)
Expand Down Expand Up @@ -107,12 +107,12 @@ TEST(LivelinessQos, ShortLiveliness_ManualByParticipant_Reliable)
PubSubWriter<HelloWorldType> writer(TEST_TOPIC_NAME);

// Write rate in milliseconds and number of samples to write
uint32_t writer_sleep_ms = 200;
uint32_t writer_sleep_ms = 500;
uint32_t num_samples = 2;

// Liveliness lease duration and announcement period, in seconds
Duration_t liveliness_s(writer_sleep_ms * 0.05 * 1e-3);
Duration_t announcement_period(writer_sleep_ms * 0.05 * 1e-3 * 0.9);
Duration_t liveliness_s(writer_sleep_ms * 0.01 * 1e-3);
Duration_t announcement_period(writer_sleep_ms * 0.01 * 1e-3 * 0.2);

reader.reliability(RELIABLE_RELIABILITY_QOS)
.liveliness_kind(MANUAL_BY_PARTICIPANT_LIVELINESS_QOS)
Expand All @@ -134,13 +134,13 @@ TEST(LivelinessQos, ShortLiveliness_ManualByParticipant_Reliable)
auto data = default_helloworld_data_generator(num_samples);
reader.startReception(data);

size_t count = 0;
unsigned int count = 0;
for (auto data_sample : data)
{
writer.send_sample(data_sample);
++count;
reader.block_for_at_least(count);
std::this_thread::sleep_for(std::chrono::milliseconds(writer_sleep_ms));
writer.send_sample(data_sample);
reader.wait_liveliness_recovered(count);
reader.wait_liveliness_lost(count);
}

EXPECT_EQ(writer.times_liveliness_lost(), num_samples);
Expand All @@ -150,7 +150,8 @@ TEST(LivelinessQos, ShortLiveliness_ManualByParticipant_Reliable)
for (count = 0; count < num_samples; count++)
{
writer.assert_liveliness();
std::this_thread::sleep_for(std::chrono::milliseconds(writer_sleep_ms));
reader.wait_liveliness_recovered(count + num_samples + 1);
reader.wait_liveliness_lost(count + num_samples + 1);
}

EXPECT_EQ(writer.times_liveliness_lost(), num_samples * 2);
Expand All @@ -168,12 +169,12 @@ TEST(LivelinessQos, ShortLiveliness_ManualByParticipant_BestEffort)
PubSubWriter<HelloWorldType> writer(TEST_TOPIC_NAME);

// Write rate in milliseconds and number of samples to write
uint32_t writer_sleep_ms = 200;
uint32_t num_samples = 3;
uint32_t writer_sleep_ms = 500;
uint32_t num_samples = 2;

// Liveliness lease duration and announcement period, in seconds
Duration_t liveliness_s(writer_sleep_ms * 0.05 * 1e-3);
Duration_t announcement_period(writer_sleep_ms * 0.05 * 1e-3 * 0.9);
Duration_t liveliness_s(writer_sleep_ms * 0.01 * 1e-3);
Duration_t announcement_period(writer_sleep_ms * 0.01 * 1e-3 * 0.2);

reader.reliability(BEST_EFFORT_RELIABILITY_QOS)
.liveliness_kind(MANUAL_BY_PARTICIPANT_LIVELINESS_QOS)
Expand All @@ -195,13 +196,13 @@ TEST(LivelinessQos, ShortLiveliness_ManualByParticipant_BestEffort)
auto data = default_helloworld_data_generator(num_samples);
reader.startReception(data);

size_t count = 0;
unsigned int count = 0;
for (auto data_sample : data)
{
writer.send_sample(data_sample);
++count;
reader.block_for_at_least(count);
std::this_thread::sleep_for(std::chrono::milliseconds(writer_sleep_ms));
writer.send_sample(data_sample);
reader.wait_liveliness_recovered(count);
reader.wait_liveliness_lost(count);
}

EXPECT_EQ(writer.times_liveliness_lost(), num_samples);
Expand All @@ -211,7 +212,8 @@ TEST(LivelinessQos, ShortLiveliness_ManualByParticipant_BestEffort)
for (count = 0; count<num_samples; count++)
{
writer.assert_liveliness();
std::this_thread::sleep_for(std::chrono::milliseconds(writer_sleep_ms));
reader.wait_liveliness_recovered(count + num_samples + 1);
reader.wait_liveliness_lost(count + num_samples + 1);
}

EXPECT_EQ(writer.times_liveliness_lost(), num_samples * 2);
Expand Down Expand Up @@ -349,8 +351,8 @@ TEST(LivelinessQos, ShortLiveliness_ManualByTopic_Reliable)
uint32_t num_samples = 3;

// Liveliness lease duration and announcement period, in seconds
Duration_t liveliness_s(writer_sleep_ms * 0.1 * 1e-3);
Duration_t announcement_period(writer_sleep_ms * 0.1 * 1e-3 * 0.9);
Duration_t liveliness_s(writer_sleep_ms * 0.05 * 1e-3);
Duration_t announcement_period(writer_sleep_ms * 0.05 * 1e-3 * 0.9);

reader.reliability(RELIABLE_RELIABILITY_QOS)
.liveliness_kind(MANUAL_BY_TOPIC_LIVELINESS_QOS)
Expand Down Expand Up @@ -643,12 +645,12 @@ TEST(LivelinessQos, ShortLiveliness_ManualByParticipant_Automatic_Reliable)
PubSubWriter<HelloWorldType> writer(TEST_TOPIC_NAME);

// Write rate in milliseconds and number of samples to write
uint32_t writer_sleep_ms = 50;
uint32_t num_samples = 3;
uint32_t writer_sleep_ms = 1000;
uint32_t num_samples = 2;

// Liveliness lease duration and announcement period, in seconds
Duration_t liveliness_s(writer_sleep_ms * 0.1 * 1e-3);
Duration_t announcement_period(writer_sleep_ms * 0.1 * 1e-3 * 0.1);
Duration_t liveliness_s(writer_sleep_ms * 0.01 * 1e-3);
Duration_t announcement_period(writer_sleep_ms * 0.01 * 1e-3 * 0.2);

reader.reliability(RELIABLE_RELIABILITY_QOS)
.liveliness_kind(AUTOMATIC_LIVELINESS_QOS)
Expand All @@ -670,13 +672,13 @@ TEST(LivelinessQos, ShortLiveliness_ManualByParticipant_Automatic_Reliable)
auto data = default_helloworld_data_generator(num_samples);
reader.startReception(data);

size_t count = 0;
unsigned int count = 0;
for (auto data_sample : data)
{
writer.send_sample(data_sample);
++count;
reader.block_for_at_least(count);
std::this_thread::sleep_for(std::chrono::milliseconds(writer_sleep_ms));
writer.send_sample(data_sample);
reader.wait_liveliness_recovered(count);
reader.wait_liveliness_lost(count);
}
EXPECT_EQ(writer.times_liveliness_lost(), num_samples);
EXPECT_EQ(reader.times_liveliness_lost(), num_samples);
Expand All @@ -685,7 +687,8 @@ TEST(LivelinessQos, ShortLiveliness_ManualByParticipant_Automatic_Reliable)
for (count = 0; count < num_samples; count++)
{
writer.assert_liveliness();
std::this_thread::sleep_for(std::chrono::milliseconds(writer_sleep_ms));
reader.wait_liveliness_recovered(num_samples + count + 1);
reader.wait_liveliness_lost(num_samples + count + 1);
}
EXPECT_EQ(writer.times_liveliness_lost(), num_samples * 2);
EXPECT_EQ(reader.times_liveliness_lost(), num_samples * 2);
Expand Down Expand Up @@ -759,12 +762,12 @@ TEST(LivelinessQos, ShortLiveliness_ManualByParticipant_Automatic_BestEffort)
PubSubWriter<HelloWorldType> writer(TEST_TOPIC_NAME);

// Write rate in milliseconds and number of samples to write
uint32_t writer_sleep_ms = 100;
uint32_t num_samples = 3;
uint32_t writer_sleep_ms = 1000;
uint32_t num_samples = 2;

// Liveliness lease duration and announcement period, in seconds
Duration_t liveliness_s(writer_sleep_ms * 0.1 * 1e-3);
Duration_t announcement_period(writer_sleep_ms * 0.1 * 1e-3 * 0.9);
Duration_t liveliness_s(writer_sleep_ms * 0.01 * 1e-3);
Duration_t announcement_period(writer_sleep_ms * 0.01 * 1e-3 * 0.2);

reader.reliability(BEST_EFFORT_RELIABILITY_QOS)
.liveliness_kind(AUTOMATIC_LIVELINESS_QOS)
Expand All @@ -786,13 +789,13 @@ TEST(LivelinessQos, ShortLiveliness_ManualByParticipant_Automatic_BestEffort)
auto data = default_helloworld_data_generator(num_samples);
reader.startReception(data);

size_t count = 0;
unsigned int count = 0;
for (auto data_sample : data)
{
writer.send_sample(data_sample);
++count;
reader.block_for_at_least(count);
std::this_thread::sleep_for(std::chrono::milliseconds(writer_sleep_ms));
writer.send_sample(data_sample);
reader.wait_liveliness_recovered(count);
reader.wait_liveliness_lost(count);
}
EXPECT_EQ(writer.times_liveliness_lost(), num_samples);
EXPECT_EQ(reader.times_liveliness_lost(), num_samples);
Expand All @@ -801,7 +804,8 @@ TEST(LivelinessQos, ShortLiveliness_ManualByParticipant_Automatic_BestEffort)
for (count = 0; count < num_samples; count++)
{
writer.assert_liveliness();
std::this_thread::sleep_for(std::chrono::milliseconds(writer_sleep_ms));
reader.wait_liveliness_recovered(num_samples + count + 1);
reader.wait_liveliness_lost(num_samples + count + 1);
}
EXPECT_EQ(writer.times_liveliness_lost(), num_samples * 2);
EXPECT_EQ(reader.times_liveliness_lost(), num_samples * 2);
Expand Down Expand Up @@ -937,12 +941,12 @@ TEST(LivelinessQos, ManualByTopic_ManualByParticipant_Reliable)
PubSubWriter<HelloWorldType> writer(TEST_TOPIC_NAME);

// Write rate in milliseconds and number of samples to write
uint32_t writer_sleep_ms = 100;
uint32_t num_samples = 3;
uint32_t writer_sleep_ms = 500;
uint32_t num_samples = 2;

// Liveliness lease duration and announcement period, in seconds
Duration_t liveliness_s(writer_sleep_ms * 0.1 * 1e-3);
Duration_t announcement_period(writer_sleep_ms * 0.1 * 1e-3 * 0.9);
Duration_t liveliness_s(writer_sleep_ms * 0.01 * 1e-3);
Duration_t announcement_period(writer_sleep_ms * 0.01 * 1e-3 * 0.2);

reader.reliability(RELIABLE_RELIABILITY_QOS)
.liveliness_kind(MANUAL_BY_PARTICIPANT_LIVELINESS_QOS)
Expand Down Expand Up @@ -996,12 +1000,12 @@ TEST(LivelinessQos, ManualByTopic_ManualByParticipant_BestEffort)
PubSubWriter<HelloWorldType> writer(TEST_TOPIC_NAME);

// Write rate in milliseconds and number of samples to write
uint32_t writer_sleep_ms = 100;
uint32_t num_samples = 3;
uint32_t writer_sleep_ms = 500;
uint32_t num_samples = 2;

// Liveliness lease duration and announcement period, in seconds
Duration_t liveliness_s(writer_sleep_ms * 0.1 * 1e-3);
Duration_t announcement_period(writer_sleep_ms * 0.1 * 1e-3 * 0.9);
Duration_t liveliness_s(writer_sleep_ms * 0.01 * 1e-3);
Duration_t announcement_period(writer_sleep_ms * 0.01 * 1e-3 * 0.2);

reader.reliability(BEST_EFFORT_RELIABILITY_QOS)
.liveliness_kind(MANUAL_BY_PARTICIPANT_LIVELINESS_QOS)
Expand Down Expand Up @@ -1055,7 +1059,7 @@ TEST(LivelinessQos, TwoWriters_OneReader_ManualByTopic)
unsigned int num_pub = 2;
unsigned int num_sub = 1;
unsigned int lease_duration_ms = 500;
unsigned int announcement_period_ms = 250;
unsigned int announcement_period_ms = 5;

// Publishers
PubSubParticipant<HelloWorldType> publishers(num_pub, 0u, 2u, 0u);
Expand Down Expand Up @@ -1223,8 +1227,8 @@ TEST(LivelinessQos, TwoWriters_TwoReaders)
{
unsigned int num_pub = 2;
unsigned int num_sub = 2;
unsigned int lease_duration_ms = 500;
unsigned int announcement_period_ms = 250;
unsigned int lease_duration_ms = 250;
unsigned int announcement_period_ms = 5;

// Publishers
PubSubParticipant<HelloWorldType> publishers(num_pub, 0u, 3u, 0u);
Expand Down Expand Up @@ -1260,12 +1264,12 @@ TEST(LivelinessQos, TwoWriters_TwoReaders)
subscribers.sub_wait_discovery();

publishers.assert_liveliness(1u);
std::this_thread::sleep_for(std::chrono::milliseconds(announcement_period_ms * 2));
std::this_thread::sleep_for(std::chrono::milliseconds(announcement_period_ms * 10));

// All three subscribers are notified that liveliness was recovered
// Both subscribers are notified that liveliness was recovered
EXPECT_EQ(subscribers.sub_times_liveliness_recovered(), 3u);

std::this_thread::sleep_for(std::chrono::milliseconds(lease_duration_ms * 2));
std::this_thread::sleep_for(std::chrono::milliseconds(lease_duration_ms * 4));
EXPECT_EQ(publishers.pub_times_liveliness_lost(), 1u);
EXPECT_EQ(subscribers.sub_times_liveliness_lost(), 1u);
}
Expand Down
8 changes: 4 additions & 4 deletions test/blackbox/PubSubReader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,18 +374,18 @@ class PubSubReader
std::cout << "Reader removal finished..." << std::endl;
}

void wait_liveliness_recovered()
void wait_liveliness_recovered(unsigned int times = 1)
{
std::unique_lock<std::mutex> lock(liveliness_mutex_);

liveliness_cv_.wait(lock, [&](){ return times_liveliness_recovered_ == 1; });
liveliness_cv_.wait(lock, [&](){ return times_liveliness_recovered_ == times; });
}

void wait_liveliness_lost()
void wait_liveliness_lost(unsigned int times = 1)
{
std::unique_lock<std::mutex> lock(liveliness_mutex_);

liveliness_cv_.wait(lock, [&]() { return times_liveliness_lost_ == 1; });
liveliness_cv_.wait(lock, [&](){ return times_liveliness_lost_ == times; });
}

#if HAVE_SECURITY
Expand Down

0 comments on commit eb2d1e7

Please sign in to comment.