Skip to content

Commit

Permalink
Select correct listener for on_requested_deadline_missed (#3423)
Browse files Browse the repository at this point in the history
* Refs #17961: Regression test for segfault

Signed-off-by: Eduardo Ponz <[email protected]>

* Refs #17961: Use the correct listener for deadline

Signed-off-by: Eduardo Ponz <[email protected]>

* Refs #17961: Fixed Windows warning regarding double to uint32 cast

Signed-off-by: Javier Santiago <[email protected]>

* Refs #17961: Test fix

Signed-off-by: Mario Dominguez <[email protected]>

---------

Signed-off-by: Eduardo Ponz <[email protected]>
Signed-off-by: Javier Santiago <[email protected]>
Signed-off-by: Mario Dominguez <[email protected]>
Co-authored-by: Javier Santiago <[email protected]>
Co-authored-by: Mario Dominguez <[email protected]>
  • Loading branch information
3 people authored Apr 14, 2023
1 parent 3a168ed commit 40411d9
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/cpp/fastdds/publisher/DataWriterImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1402,7 +1402,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 @@ -279,6 +281,94 @@ TEST_P(DDSDataWriter, WithTimestampOperations)
EXPECT_EQ(ReturnCode_t::RETCODE_OK, datareader.return_loan(datas, infos));
}

/**
* 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

0 comments on commit 40411d9

Please sign in to comment.