Skip to content

Commit

Permalink
Fixed offline publish test.
Browse files Browse the repository at this point in the history
The published messages during offline should be sent only if the session
exists in the broker.
If offline publish is sent after session has been expired is a protocol error.
  • Loading branch information
redboltz committed Dec 18, 2020
1 parent 3b085ae commit a5d9118
Showing 1 changed file with 24 additions and 22 deletions.
46 changes: 24 additions & 22 deletions test/system/st_offline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ BOOST_AUTO_TEST_SUITE(st_offline)

template <typename Client>
inline void connect_no_clean(Client& c) {
c->set_clean_session(false);
if (c->get_protocol_version() == MQTT_NS::protocol_version::v5) {
c->set_clean_start(false);
c->connect(
MQTT_NS::v5::properties{
MQTT_NS::v5::property::session_expiry_interval(
Expand All @@ -24,14 +24,15 @@ inline void connect_no_clean(Client& c) {
);
}
else {
c->set_clean_session(false);
c->connect();
}
}

template <typename Client>
inline void async_connect_no_clean(Client& c) {
c->set_clean_session(false);
if (c->get_protocol_version() == MQTT_NS::protocol_version::v5) {
c->set_clean_start(false);
c->async_connect(
std::vector<MQTT_NS::v5::property_variant>{
MQTT_NS::v5::property::session_expiry_interval(
Expand All @@ -41,6 +42,7 @@ inline void async_connect_no_clean(Client& c) {
);
}
else {
c->set_clean_session(false);
c->async_connect();
}
}
Expand Down Expand Up @@ -84,7 +86,8 @@ BOOST_AUTO_TEST_CASE( publish_qos1 ) {
"h_close1",
[&] {
MQTT_CHK("h_connack2");
BOOST_TEST(sp == false);
// Offline publish is enabled only if session is not expired in the broker
BOOST_TEST(sp == true);
}
);
BOOST_TEST(ret);
Expand Down Expand Up @@ -114,9 +117,8 @@ BOOST_AUTO_TEST_CASE( publish_qos1 ) {
"h_close1",
[&] {
MQTT_CHK("h_connack2");
// The previous connection is not set Session Expiry Interval.
// That means session state is cleared on close.
BOOST_TEST(sp == false);
// Offline publish is enabled only if session is not expired in the broker
BOOST_TEST(sp == true);
}
);
BOOST_TEST(ret);
Expand Down Expand Up @@ -161,7 +163,7 @@ BOOST_AUTO_TEST_CASE( publish_qos1 ) {
BOOST_CHECK(false);
});
MQTT_CHK("start");
c->connect();
connect_no_clean(c);
ioc.run();
BOOST_TEST(chk.all());
};
Expand Down Expand Up @@ -208,7 +210,8 @@ BOOST_AUTO_TEST_CASE( publish_qos2 ) {
"h_close1",
[&] {
MQTT_CHK("h_connack2");
BOOST_TEST(sp == false);
// Offline publish is enabled only if session is not expired in the broker
BOOST_TEST(sp == true);
}
);
BOOST_TEST(ret);
Expand Down Expand Up @@ -245,9 +248,8 @@ BOOST_AUTO_TEST_CASE( publish_qos2 ) {
"h_close1",
[&] {
MQTT_CHK("h_connack2");
// The previous connection is not set Session Expiry Interval.
// That means session state is cleared on close.
BOOST_TEST(sp == false);
// Offline publish is enabled only if session is not expired in the broker
BOOST_TEST(sp == true);
}
);
BOOST_TEST(ret);
Expand Down Expand Up @@ -299,7 +301,7 @@ BOOST_AUTO_TEST_CASE( publish_qos2 ) {
BOOST_CHECK(false);
});
MQTT_CHK("start");
c->connect();
connect_no_clean(c);
ioc.run();
BOOST_TEST(chk.all());
};
Expand Down Expand Up @@ -348,7 +350,8 @@ BOOST_AUTO_TEST_CASE( multi_publish_qos1 ) {
"h_close1",
[&] {
MQTT_CHK("h_connack2");
BOOST_TEST(sp == false);
// Offline publish is enabled only if session is not expired in the broker
BOOST_TEST(sp == true);
}
);
BOOST_TEST(ret);
Expand Down Expand Up @@ -389,9 +392,8 @@ BOOST_AUTO_TEST_CASE( multi_publish_qos1 ) {
"h_close1",
[&] {
MQTT_CHK("h_connack2");
// The previous connection is not set Session Expiry Interval.
// That means session state is cleared on close.
BOOST_TEST(sp == false);
// Offline publish is enabled only if session is not expired in the broker
BOOST_TEST(sp == true);
}
);
BOOST_TEST(ret);
Expand Down Expand Up @@ -448,7 +450,7 @@ BOOST_AUTO_TEST_CASE( multi_publish_qos1 ) {
BOOST_CHECK(false);
});
MQTT_CHK("start");
c->connect();
connect_no_clean(c);
ioc.run();
BOOST_TEST(chk.all());
};
Expand Down Expand Up @@ -495,7 +497,8 @@ BOOST_AUTO_TEST_CASE( async_publish_qos1 ) {
"h_pub_finish",
[&] {
MQTT_CHK("h_connack2");
BOOST_TEST(sp == false);
// Offline publish is enabled only if session is not expired in the broker
BOOST_TEST(sp == true);
}
);
BOOST_TEST(ret);
Expand Down Expand Up @@ -525,9 +528,8 @@ BOOST_AUTO_TEST_CASE( async_publish_qos1 ) {
"h_pub_finish",
[&] {
MQTT_CHK("h_connack2");
// The previous connection is not set Session Expiry Interval.
// That means session state is cleared on close.
BOOST_TEST(sp == false);
// Offline publish is enabled only if session is not expired in the broker
BOOST_TEST(sp == true);
}
);
BOOST_TEST(ret);
Expand Down Expand Up @@ -582,7 +584,7 @@ BOOST_AUTO_TEST_CASE( async_publish_qos1 ) {
BOOST_CHECK(false);
});
MQTT_CHK("start");
c->async_connect();
async_connect_no_clean(c);
ioc.run();
BOOST_TEST(chk.all());
};
Expand Down

0 comments on commit a5d9118

Please sign in to comment.