|
10 | 10 |
|
11 | 11 | BOOST_AUTO_TEST_SUITE(test_offline)
|
12 | 12 |
|
| 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 | + |
13 | 25 | BOOST_AUTO_TEST_CASE( publish_qos1 ) {
|
14 | 26 | auto test = [](boost::asio::io_context& ioc, auto& c, auto& s, auto& /*b*/) {
|
15 | 27 | using packet_id_t = typename std::remove_reference_t<decltype(*c)>::packet_id_t;
|
@@ -79,13 +91,9 @@ BOOST_AUTO_TEST_CASE( publish_qos1 ) {
|
79 | 91 | "h_close1",
|
80 | 92 | [&] {
|
81 | 93 | 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); |
89 | 97 | }
|
90 | 98 | );
|
91 | 99 | BOOST_TEST(ret);
|
@@ -114,8 +122,7 @@ BOOST_AUTO_TEST_CASE( publish_qos1 ) {
|
114 | 122 | MQTT_CHK("h_close1");
|
115 | 123 | // offline publish
|
116 | 124 | 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); |
119 | 126 | },
|
120 | 127 | "h_puback",
|
121 | 128 | [&] {
|
@@ -215,13 +222,9 @@ BOOST_AUTO_TEST_CASE( publish_qos2 ) {
|
215 | 222 | "h_close1",
|
216 | 223 | [&] {
|
217 | 224 | 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); |
225 | 228 | }
|
226 | 229 | );
|
227 | 230 | BOOST_TEST(ret);
|
@@ -257,8 +260,7 @@ BOOST_AUTO_TEST_CASE( publish_qos2 ) {
|
257 | 260 | MQTT_CHK("h_close1");
|
258 | 261 | // offline publish
|
259 | 262 | 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); |
262 | 264 | },
|
263 | 265 | "h_pubcomp",
|
264 | 266 | [&] {
|
@@ -364,13 +366,9 @@ BOOST_AUTO_TEST_CASE( multi_publish_qos1 ) {
|
364 | 366 | "h_close1",
|
365 | 367 | [&] {
|
366 | 368 | 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); |
374 | 372 | }
|
375 | 373 | );
|
376 | 374 | BOOST_TEST(ret);
|
@@ -411,8 +409,7 @@ BOOST_AUTO_TEST_CASE( multi_publish_qos1 ) {
|
411 | 409 | // offline publish
|
412 | 410 | pid_pub1 = c->publish(/*topic_base()*/ + "987/topic1", "topic1_contents1", MQTT_NS::qos::at_least_once);
|
413 | 411 | 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); |
416 | 413 | },
|
417 | 414 | "h_puback2",
|
418 | 415 | [&] {
|
@@ -505,13 +502,9 @@ BOOST_AUTO_TEST_CASE( async_publish_qos1 ) {
|
505 | 502 | "h_pub_finish",
|
506 | 503 | [&] {
|
507 | 504 | 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); |
515 | 508 | }
|
516 | 509 | );
|
517 | 510 | BOOST_TEST(ret);
|
@@ -549,8 +542,7 @@ BOOST_AUTO_TEST_CASE( async_publish_qos1 ) {
|
549 | 542 | MQTT_CHK("h_pub_finish");
|
550 | 543 | }
|
551 | 544 | );
|
552 |
| - c->set_clean_session(false); |
553 |
| - c->connect(); |
| 545 | + connect_no_clean(c); |
554 | 546 | },
|
555 | 547 | "h_puback",
|
556 | 548 | [&] {
|
|
0 commit comments