Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[17961] Select correct listener for on_requested_deadline_missed (backport #3423) #3453

Merged
merged 1 commit into from
May 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/cpp/fastdds/publisher/DataWriterImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1304,7 +1304,7 @@ bool DataWriterImpl::deadline_missed()
auto listener = get_listener_for(notify_status);
if (nullptr != listener)
{
listener_->on_offered_deadline_missed(user_datawriter_, deadline_missed_status_);
listener->on_offered_deadline_missed(user_datawriter_, deadline_missed_status_);
deadline_missed_status_.total_count_change = 0;
}
user_datawriter_->get_statuscondition().get_impl()->set_status(notify_status, true);
Expand Down
90 changes: 90 additions & 0 deletions test/blackbox/common/DDSBlackboxTestsDataWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include <chrono>

#include "BlackboxTests.hpp"

#include "PubSubReader.hpp"
Expand Down Expand Up @@ -197,6 +199,94 @@ TEST_P(DDSDataWriter, GetKeyValue)
EXPECT_EQ(valid_data.key(), data.key());
}

/**
* Regression test for EasyRedmine issue https://eprosima.easyredmine.com/issues/17961
*
* The test:
* 1. Creates a DomainParticipant with a listener which captures the offered_deadline_missed
* events.
* 2. Creates a DataWriter with a 1 ms deadline period, without any listener and that never
* publishes data.
* 3. Wait for the deadline callback to be triggered at least once within a second.
* 4. Checks that the callback was indeed triggered.
*/

TEST(DDSDataWriter, OfferedDeadlineMissedListener)
{
using namespace eprosima::fastdds::dds;

class WriterWrapper : public DomainParticipantListener
{
public:

WriterWrapper(
std::condition_variable& cv,
std::atomic_bool& deadline_called)
: cv_(cv)
, deadline_called_(deadline_called)
{
StatusMask status_mask = StatusMask::none();
status_mask << StatusMask::offered_deadline_missed();
participant_ = DomainParticipantFactory::get_instance()->create_participant(0, PARTICIPANT_QOS_DEFAULT,
this, status_mask);

type_support_.reset(new HelloWorldPubSubType());
type_support_.register_type(participant_, "DeadlineListenerTest");

topic_ = participant_->create_topic("deadline_listener_test", "DeadlineListenerTest", TOPIC_QOS_DEFAULT);

publisher_ = participant_->create_publisher(PUBLISHER_QOS_DEFAULT);

DataWriterQos dw_qos = DATAWRITER_QOS_DEFAULT;
dw_qos.deadline().period = Time_t(0, 1000000);
datawriter_ = publisher_->create_datawriter(
topic_,
dw_qos);

// Apparently the time is not started until the first data is published
HelloWorld data;
datawriter_->write(&data);
}

virtual ~WriterWrapper()
{
participant_->delete_contained_entities();
DomainParticipantFactory::get_instance()->delete_participant(participant_);
}

void on_offered_deadline_missed(
DataWriter* /* writer */,
const OfferedDeadlineMissedStatus& /* status */) override
{
deadline_called_.store(true);
cv_.notify_one();
}

protected:

std::condition_variable& cv_;
std::atomic_bool& deadline_called_;
DomainParticipant* participant_;
TypeSupport type_support_;
Topic* topic_;
Publisher* publisher_;
DataWriter* datawriter_;
};

std::mutex mtx;
std::condition_variable cv;
std::atomic_bool deadline_called{false};
std::unique_lock<std::mutex> lck(mtx);

WriterWrapper writer_w(cv, deadline_called);

auto ret = cv.wait_for(lck, std::chrono::seconds(1), [&]()
{
return deadline_called.load();
});
ASSERT_TRUE(ret);
}

#ifdef INSTANTIATE_TEST_SUITE_P
#define GTEST_INSTANTIATE_TEST_MACRO(x, y, z, w) INSTANTIATE_TEST_SUITE_P(x, y, z, w)
#else
Expand Down