Skip to content

Commit

Permalink
add a regression test
Browse files Browse the repository at this point in the history
Signed-off-by: Chen Lihui <lihui.chen@sony.com>
  • Loading branch information
Chen Lihui committed Nov 15, 2022
1 parent 744524a commit db53f1a
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion test/unittest/dds/core/condition/WaitSetImplTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

#include <algorithm>
#include <future>

#include <gtest/gtest.h>

Expand All @@ -33,7 +34,7 @@ class TestCondition : public Condition
{
public:

bool trigger_value = false;
volatile bool trigger_value = false;

bool get_trigger_value() const override
{
Expand Down Expand Up @@ -197,6 +198,47 @@ TEST(WaitSetImplTests, wait)
}
}

TEST(WaitSetImplTests, fix_wait_notification_lost)
{
ConditionSeq conditions;
WaitSetImpl wait_set;

// Waiting should return the added connection while the condition triggered
{
TestCondition triggered_condition;

// Expecting calls on the notifier of triggered_condition
auto notifier = triggered_condition.get_notifier();
EXPECT_CALL(*notifier, attach_to(_)).Times(1);
EXPECT_CALL(*notifier, will_be_deleted(_)).Times(1);
wait_set.attach_condition(triggered_condition);

std::promise<void> promise;
std::future<void> future = promise.get_future();
ReturnCode_t ret = ReturnCode_t::RETCODE_ERROR;
std::thread add_triggered_condition([&]()
{
// not to use `WaitSetImpl::wait` with a timeout value, because the
// `condition_variable::wait_for` could call _Predicate function again
// after timeout in the `WaitSetImpl::wait`.
ret = wait_set.wait(conditions, eprosima::fastrtps::c_TimeInfinite);
promise.set_value();
});

triggered_condition.trigger_value = true;
wait_set.wake_up();

// expect to get notification after wake_up, otherwise output error within 5 seconds
future.wait_for(std::chrono::seconds(5));
ASSERT_EQ(ReturnCode_t::RETCODE_OK, ret);
EXPECT_EQ(1u, conditions.size());
EXPECT_NE(conditions.cend(), std::find(conditions.cbegin(), conditions.cend(), &triggered_condition));
add_triggered_condition.join();

wait_set.will_be_deleted(triggered_condition);
}
}

int main(
int argc,
char** argv)
Expand Down

0 comments on commit db53f1a

Please sign in to comment.