Skip to content

Commit 8d11b53

Browse files
committed
Fixed tests.
Removed redundant handler reset code from test_broker. Added minimal support for Session Expiry Interval. Timer is not set yet.
1 parent b929e5b commit 8d11b53

6 files changed

+565
-285
lines changed

test/connect.cpp

+19-8
Original file line numberDiff line numberDiff line change
@@ -566,13 +566,9 @@ BOOST_AUTO_TEST_CASE( noclean ) {
566566
break;
567567
case 3:
568568
MQTT_CHK("h_connack4");
569-
// If clean session is not provided, than there will be a session present
570-
// if there was ever a previous connection, even if clean session was provided
571-
// on the previous connection.
572-
// This is because MQTTv5 change the semantics of the flag to "clean start"
573-
// such that it only effects the start of the session.
574-
// Post Session cleanup is handled with a timer, not with the clean session flag.
575-
BOOST_TEST(sp == true);
569+
// The previous connection is not set Session Expiry Interval.
570+
// That means session state is cleared on close.
571+
BOOST_TEST(sp == false);
576572
break;
577573
}
578574
BOOST_TEST(connack_return_code == MQTT_NS::v5::connect_reason_code::success);
@@ -603,7 +599,22 @@ BOOST_AUTO_TEST_CASE( noclean ) {
603599
case 2:
604600
MQTT_CHK("h_close3");
605601
c->set_clean_session(false);
606-
c->connect();
602+
switch (c->get_protocol_version()) {
603+
case MQTT_NS::protocol_version::v3_1_1:
604+
c->connect();
605+
break;
606+
case MQTT_NS::protocol_version::v5:
607+
// set session_expiry_interval as infinity.
608+
c->connect(
609+
std::vector<MQTT_NS::v5::property_variant>{
610+
MQTT_NS::v5::property::session_expiry_interval(0xFFFFFFFFUL)
611+
}
612+
);
613+
break;
614+
default:
615+
BOOST_CHECK(false);
616+
break;
617+
}
607618
++connect;
608619
break;
609620
case 3:

test/offline.cpp

+28-36
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,18 @@
1010

1111
BOOST_AUTO_TEST_SUITE(test_offline)
1212

13+
template <typename Client>
14+
inline void connect_no_clean(Client& c) {
15+
c->set_clean_session(false);
16+
if (c->get_protocol_version() == MQTT_NS::protocol_version::v5) {
17+
// set session_expiry_interval as infinity.
18+
c->connect(std::vector<MQTT_NS::v5::property_variant>{MQTT_NS::v5::property::session_expiry_interval(0xFFFFFFFFUL)});
19+
}
20+
else {
21+
c->connect();
22+
}
23+
}
24+
1325
BOOST_AUTO_TEST_CASE( publish_qos1 ) {
1426
auto test = [](boost::asio::io_context& ioc, auto& c, auto& s, auto& /*b*/) {
1527
using packet_id_t = typename std::remove_reference_t<decltype(*c)>::packet_id_t;
@@ -79,13 +91,9 @@ BOOST_AUTO_TEST_CASE( publish_qos1 ) {
7991
"h_close1",
8092
[&] {
8193
MQTT_CHK("h_connack2");
82-
// If clean session is not provided, than there will be a session present
83-
// if there was ever a previous connection, even if clean session was provided
84-
// on the previous connection.
85-
// This is because MQTTv5 change the semantics of the flag to "clean start"
86-
// such that it only effects the start of the session.
87-
// Post Session cleanup is handled with a timer, not with the clean session flag.
88-
BOOST_TEST(sp == true);
94+
// The previous connection is not set Session Expiry Interval.
95+
// That means session state is cleared on close.
96+
BOOST_TEST(sp == false);
8997
}
9098
);
9199
BOOST_TEST(ret);
@@ -114,8 +122,7 @@ BOOST_AUTO_TEST_CASE( publish_qos1 ) {
114122
MQTT_CHK("h_close1");
115123
// offline publish
116124
pid_pub = c->publish("topic1", "topic1_contents", MQTT_NS::qos::at_least_once);
117-
c->set_clean_session(false);
118-
c->connect();
125+
connect_no_clean(c);
119126
},
120127
"h_puback",
121128
[&] {
@@ -215,13 +222,9 @@ BOOST_AUTO_TEST_CASE( publish_qos2 ) {
215222
"h_close1",
216223
[&] {
217224
MQTT_CHK("h_connack2");
218-
// If clean session is not provided, than there will be a session present
219-
// if there was ever a previous connection, even if clean session was provided
220-
// on the previous connection.
221-
// This is because MQTTv5 change the semantics of the flag to "clean start"
222-
// such that it only effects the start of the session.
223-
// Post Session cleanup is handled with a timer, not with the clean session flag.
224-
BOOST_TEST(sp == true);
225+
// The previous connection is not set Session Expiry Interval.
226+
// That means session state is cleared on close.
227+
BOOST_TEST(sp == false);
225228
}
226229
);
227230
BOOST_TEST(ret);
@@ -257,8 +260,7 @@ BOOST_AUTO_TEST_CASE( publish_qos2 ) {
257260
MQTT_CHK("h_close1");
258261
// offline publish
259262
pid_pub = c->publish("topic1", "topic1_contents", MQTT_NS::qos::exactly_once);
260-
c->set_clean_session(false);
261-
c->connect();
263+
connect_no_clean(c);
262264
},
263265
"h_pubcomp",
264266
[&] {
@@ -364,13 +366,9 @@ BOOST_AUTO_TEST_CASE( multi_publish_qos1 ) {
364366
"h_close1",
365367
[&] {
366368
MQTT_CHK("h_connack2");
367-
// If clean session is not provided, than there will be a session present
368-
// if there was ever a previous connection, even if clean session was provided
369-
// on the previous connection.
370-
// This is because MQTTv5 change the semantics of the flag to "clean start"
371-
// such that it only effects the start of the session.
372-
// Post Session cleanup is handled with a timer, not with the clean session flag.
373-
BOOST_TEST(sp == true);
369+
// The previous connection is not set Session Expiry Interval.
370+
// That means session state is cleared on close.
371+
BOOST_TEST(sp == false);
374372
}
375373
);
376374
BOOST_TEST(ret);
@@ -411,8 +409,7 @@ BOOST_AUTO_TEST_CASE( multi_publish_qos1 ) {
411409
// offline publish
412410
pid_pub1 = c->publish(/*topic_base()*/ + "987/topic1", "topic1_contents1", MQTT_NS::qos::at_least_once);
413411
pid_pub2 = c->publish(/*topic_base()*/ + "987/topic1", "topic1_contents2", MQTT_NS::qos::at_least_once);
414-
c->set_clean_session(false);
415-
c->connect();
412+
connect_no_clean(c);
416413
},
417414
"h_puback2",
418415
[&] {
@@ -505,13 +502,9 @@ BOOST_AUTO_TEST_CASE( async_publish_qos1 ) {
505502
"h_pub_finish",
506503
[&] {
507504
MQTT_CHK("h_connack2");
508-
// If clean session is not provided, than there will be a session present
509-
// if there was ever a previous connection, even if clean session was provided
510-
// on the previous connection.
511-
// This is because MQTTv5 change the semantics of the flag to "clean start"
512-
// such that it only effects the start of the session.
513-
// Post Session cleanup is handled with a timer, not with the clean session flag.
514-
BOOST_TEST(sp == true);
505+
// The previous connection is not set Session Expiry Interval.
506+
// That means session state is cleared on close.
507+
BOOST_TEST(sp == false);
515508
}
516509
);
517510
BOOST_TEST(ret);
@@ -549,8 +542,7 @@ BOOST_AUTO_TEST_CASE( async_publish_qos1 ) {
549542
MQTT_CHK("h_pub_finish");
550543
}
551544
);
552-
c->set_clean_session(false);
553-
c->connect();
545+
connect_no_clean(c);
554546
},
555547
"h_puback",
556548
[&] {

0 commit comments

Comments
 (0)