mqtt5 0.32.0

Complete MQTT v5.0 platform with high-performance async client and full-featured broker supporting TCP, TLS, WebSocket, authentication, bridging, and resource monitoring
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
#![allow(clippy::large_futures)]

mod common;
use common::TestBroker;

use mqtt5::time::Duration;
use mqtt5::{ConnectOptions, MqttClient, QoS};
use std::sync::atomic::{AtomicBool, AtomicU32, Ordering};
use std::sync::Arc;
use tokio::time::sleep;

#[tokio::test]
async fn test_clean_start_true() {
    // Start test broker
    let broker = TestBroker::start().await;

    let options = ConnectOptions::new("clean-start-true").with_clean_start(true);

    let client = MqttClient::with_options(options);

    // First connection
    let session_present = client
        .connect_with_options(
            broker.address(),
            ConnectOptions::new("clean-start-true").with_clean_start(true),
        )
        .await
        .unwrap();

    assert!(
        !session_present.session_present,
        "First connection should not have session present"
    );

    // Subscribe to a topic
    client.subscribe("test/clean", |_| {}).await.unwrap();

    client.disconnect().await.unwrap();

    // Second connection with clean_start=true
    let session_present = client
        .connect_with_options(
            broker.address(),
            ConnectOptions::new("clean-start-true").with_clean_start(true),
        )
        .await
        .unwrap();

    assert!(
        !session_present.session_present,
        "Clean start should not restore session"
    );

    client.disconnect().await.unwrap();
}

#[tokio::test]
async fn test_clean_start_false() {
    // Start test broker
    let broker = TestBroker::start().await;

    let client_id = "persist-test-1";

    // First connection with clean_start=true to ensure clean slate
    let client1 = MqttClient::with_options(ConnectOptions::new(client_id).with_clean_start(true));
    client1.connect(broker.address()).await.unwrap();

    // Subscribe to topics
    client1.subscribe("test/persist/1", |_| {}).await.unwrap();
    client1.subscribe("test/persist/2", |_| {}).await.unwrap();

    client1.disconnect().await.unwrap();

    // Second connection with clean_start=false
    let client2 = MqttClient::with_options(ConnectOptions::new(client_id).with_clean_start(false));

    let session_present = client2
        .connect_with_options(
            broker.address(),
            ConnectOptions::new(client_id).with_clean_start(false),
        )
        .await
        .unwrap();

    // Note: Some brokers may not preserve sessions even with clean_start=false
    let session_present_flag = session_present.session_present;
    println!("Session present: {session_present_flag}");
    if !session_present.session_present {
        println!("Warning: Broker did not preserve session. This is broker-dependent behavior.");
    }

    // Subscriptions should still be active
    // Test by publishing to the subscribed topics
    let received = Arc::new(AtomicU32::new(0));
    let received_clone = received.clone();

    // Re-subscribe to set up callback (broker maintains subscription but we need local callback)
    client2
        .subscribe("test/persist/1", move |_| {
            received_clone.fetch_add(1, Ordering::Relaxed);
        })
        .await
        .unwrap();

    client2.publish("test/persist/1", "test").await.unwrap();
    sleep(Duration::from_millis(500)).await;

    // Only check if session was actually preserved
    if session_present.session_present {
        assert!(
            received.load(Ordering::Relaxed) > 0,
            "Should receive message on persisted subscription"
        );
    }

    client2.disconnect().await.unwrap();
}

#[tokio::test]
async fn test_session_expiry_interval() {
    // Start test broker
    let broker = TestBroker::start().await;

    let client_id = "session-expiry-test";

    // Connect with session expiry interval
    let options = ConnectOptions::new(client_id)
        .with_clean_start(false)
        .with_session_expiry_interval(5); // 5 seconds

    let client1 = MqttClient::with_options(options.clone());
    client1.connect(broker.address()).await.unwrap();

    // Subscribe to a topic
    client1.subscribe("test/expiry", |_| {}).await.unwrap();

    client1.disconnect().await.unwrap();

    // Wait less than expiry interval
    sleep(Duration::from_secs(2)).await;

    // Reconnect - session should still exist
    let client2 = MqttClient::with_options(options.clone());
    let session_present = client2
        .connect_with_options(broker.address(), options.clone())
        .await
        .unwrap();

    assert!(
        session_present.session_present,
        "Session should exist within expiry interval"
    );
    client2.disconnect().await.unwrap();

    // Wait for session to expire
    sleep(Duration::from_secs(4)).await;

    // Reconnect - session should be gone
    let client3 = MqttClient::with_options(options);
    let session_present = client3
        .connect_with_options(
            broker.address(),
            ConnectOptions::new(client_id).with_clean_start(false),
        )
        .await
        .unwrap();

    // Broker might not have expired it yet, so we don't assert here
    println!(
        "Session present after expiry: {}",
        session_present.session_present
    );

    client3.disconnect().await.unwrap();
}

#[tokio::test]
async fn test_qos1_message_persistence() {
    // Start test broker
    let broker = TestBroker::start().await;

    let pub_client = MqttClient::new("persist-pub");
    let sub_client_id = "persist-sub-qos1";

    // Subscriber connects and subscribes
    let sub_options = ConnectOptions::new(sub_client_id).with_clean_start(false);
    let sub_client = MqttClient::with_options(sub_options);

    sub_client.connect(broker.address()).await.unwrap();
    sub_client
        .subscribe_with_options(
            "test/persist/qos1",
            mqtt5::SubscribeOptions {
                qos: QoS::AtLeastOnce,
                ..Default::default()
            },
            |_| {},
        )
        .await
        .unwrap();

    // Disconnect subscriber
    sub_client.disconnect().await.unwrap();

    // Publisher sends QoS 1 messages while subscriber is offline
    pub_client.connect(broker.address()).await.unwrap();

    for i in 0..5 {
        pub_client
            .publish_qos1("test/persist/qos1", format!("Offline message {i}"))
            .await
            .unwrap();
    }

    pub_client.disconnect().await.unwrap();

    // Subscriber reconnects
    let received = Arc::new(AtomicU32::new(0));
    let received_clone = received.clone();

    let sub_client2 =
        MqttClient::with_options(ConnectOptions::new(sub_client_id).with_clean_start(false));

    let session_present = sub_client2
        .connect_with_options(
            broker.address(),
            ConnectOptions::new(sub_client_id).with_clean_start(false),
        )
        .await
        .unwrap();

    println!(
        "Session present after reconnect: {}",
        session_present.session_present
    );
    if !session_present.session_present {
        println!("Warning: Broker did not restore session for QoS persistence test");
    }

    // Re-subscribe to set callback
    sub_client2
        .subscribe_with_options(
            "test/persist/qos1",
            mqtt5::SubscribeOptions {
                qos: QoS::AtLeastOnce,
                ..Default::default()
            },
            move |_| {
                received_clone.fetch_add(1, Ordering::Relaxed);
            },
        )
        .await
        .unwrap();

    // Wait for queued messages
    sleep(Duration::from_secs(2)).await;

    let count = received.load(Ordering::Relaxed);
    println!("Received {count} offline messages");
    // Only assert if session was preserved
    if session_present.session_present {
        assert!(
            count > 0,
            "Should receive some offline messages when session is preserved"
        );
    }

    match sub_client2.disconnect().await {
        Ok(()) | Err(mqtt5::MqttError::NotConnected) => {}
        Err(e) => panic!("unexpected disconnect error: {e}"),
    }
}

#[tokio::test]
async fn test_qos2_message_persistence() {
    // Start test broker
    let broker = TestBroker::start().await;

    let pub_client = MqttClient::new("persist-pub-qos2");
    let sub_client_id = "persist-sub-qos2";

    // Subscriber connects and subscribes with QoS 2
    let sub_options = ConnectOptions::new(sub_client_id).with_clean_start(false);
    let sub_client = MqttClient::with_options(sub_options);

    sub_client.connect(broker.address()).await.unwrap();
    sub_client
        .subscribe_with_options(
            "test/persist/qos2",
            mqtt5::SubscribeOptions {
                qos: QoS::ExactlyOnce,
                ..Default::default()
            },
            |_| {},
        )
        .await
        .unwrap();

    // Disconnect subscriber
    sub_client.disconnect().await.unwrap();

    // Publisher sends QoS 2 messages while subscriber is offline
    pub_client.connect(broker.address()).await.unwrap();

    for i in 0..3 {
        pub_client
            .publish_qos2("test/persist/qos2", format!("QoS2 offline message {i}"))
            .await
            .unwrap();
    }

    pub_client.disconnect().await.unwrap();

    // Subscriber reconnects
    let messages = Arc::new(std::sync::Mutex::new(Vec::new()));
    let messages_clone = messages.clone();

    let sub_client2 =
        MqttClient::with_options(ConnectOptions::new(sub_client_id).with_clean_start(false));

    sub_client2.connect(broker.address()).await.unwrap();

    // Re-subscribe to set callback
    sub_client2
        .subscribe_with_options(
            "test/persist/qos2",
            mqtt5::SubscribeOptions {
                qos: QoS::ExactlyOnce,
                ..Default::default()
            },
            move |msg| {
                messages_clone
                    .lock()
                    .unwrap()
                    .push(String::from_utf8_lossy(&msg.payload).to_string());
            },
        )
        .await
        .unwrap();

    // Wait for queued messages
    sleep(Duration::from_secs(2)).await;

    {
        let msgs = messages.lock().unwrap();
        let msg_count = msgs.len();
        println!("Received {msg_count} QoS 2 offline messages");

        // Should receive exactly once
        let mut unique_msgs = msgs.clone();
        unique_msgs.sort();
        unique_msgs.dedup();
        assert_eq!(msgs.len(), unique_msgs.len(), "No duplicate QoS 2 messages");
    } // Drop the lock before awaiting

    match sub_client2.disconnect().await {
        Ok(()) | Err(mqtt5::MqttError::NotConnected) => {}
        Err(e) => panic!("unexpected disconnect error: {e}"),
    }
}

#[tokio::test]
async fn test_subscription_persistence() {
    // Start test broker
    let broker = TestBroker::start().await;

    let client_id = "sub-persist-test";

    // First connection - subscribe to multiple topics
    let client1 = MqttClient::with_options(ConnectOptions::new(client_id).with_clean_start(true));
    client1.connect(broker.address()).await.unwrap();

    client1.subscribe("test/sub/1", |_| {}).await.unwrap();
    client1.subscribe("test/sub/2", |_| {}).await.unwrap();
    client1.subscribe("test/sub/+", |_| {}).await.unwrap();

    client1.disconnect().await.unwrap();

    // Second connection - subscriptions should persist
    let received_topics = Arc::new(std::sync::Mutex::new(Vec::new()));
    let received_topics_clone = received_topics.clone();

    let client2 = MqttClient::with_options(ConnectOptions::new(client_id).with_clean_start(false));

    let session_present = client2
        .connect_with_options(
            broker.address(),
            ConnectOptions::new(client_id).with_clean_start(false),
        )
        .await
        .unwrap();

    println!(
        "Session present for subscription persistence: {}",
        session_present.session_present
    );
    if !session_present.session_present {
        println!("Warning: Broker did not preserve session for subscription test");
        // Skip the rest of the test if session wasn't preserved
        client2.disconnect().await.unwrap();
        return;
    }

    // Need to re-subscribe to set local callbacks
    // (broker maintains subscriptions but we need local handlers)
    client2
        .subscribe("test/sub/+", move |msg| {
            received_topics_clone
                .lock()
                .unwrap()
                .push(msg.topic.clone());
        })
        .await
        .unwrap();

    // Publish to subscribed topics
    client2.publish("test/sub/1", "msg1").await.unwrap();
    client2.publish("test/sub/2", "msg2").await.unwrap();
    client2.publish("test/sub/3", "msg3").await.unwrap();

    sleep(Duration::from_millis(500)).await;

    {
        let topics = received_topics.lock().unwrap();
        assert!(
            topics.len() >= 3,
            "Should receive messages on persisted subscriptions"
        );
    } // Drop the lock before awaiting

    client2.disconnect().await.unwrap();
}

#[tokio::test]
async fn test_will_message_persistence() {
    // Start test broker
    let broker = TestBroker::start().await;

    let will_client_id = "will-persist-test";
    let sub_client = MqttClient::new("will-sub");

    // Subscribe to will topic
    sub_client.connect(broker.address()).await.unwrap();

    let will_received = Arc::new(AtomicBool::new(false));
    let will_received_clone = will_received.clone();

    sub_client
        .subscribe("test/will/persist", move |msg| {
            println!(
                "Received will message: {:?}",
                String::from_utf8_lossy(&msg.payload)
            );
            will_received_clone.store(true, Ordering::Relaxed);
        })
        .await
        .unwrap();

    // Connect with will message and persistent session
    let will_msg = mqtt5::WillMessage::new("test/will/persist", "Client died")
        .with_qos(QoS::AtLeastOnce)
        .with_retain(false);

    let will_options = ConnectOptions::new(will_client_id)
        .with_clean_start(false)
        .with_will(will_msg);

    let will_client = MqttClient::with_options(will_options);
    will_client.connect(broker.address()).await.unwrap();

    // Simulate abnormal disconnection by dropping the client
    // This causes the TCP connection to close without sending DISCONNECT
    drop(will_client);

    // Wait for will message
    sleep(Duration::from_secs(2)).await;

    // Will message delivery depends on broker implementation
    let received = will_received.load(Ordering::Relaxed);
    println!("Will message received: {received}");
    if !received {
        println!("Warning: Will message not received. This may be due to broker configuration or the connection not being detected as abnormal.");
    }

    sub_client.disconnect().await.unwrap();
}

#[tokio::test]
async fn test_packet_id_persistence() {
    // Start test broker
    let broker = TestBroker::start().await;

    // Test that packet IDs are managed correctly across reconnections
    let client_id = "packet-id-persist";

    let options = ConnectOptions::new(client_id).with_clean_start(false);
    let client1 = MqttClient::with_options(options.clone());

    client1.connect(broker.address()).await.unwrap();

    // Send some QoS 1 messages to allocate packet IDs
    let mut first_ids = Vec::new();
    for i in 0..5 {
        let id = client1
            .publish_qos1("test/pid", format!("Message {i}"))
            .await
            .unwrap();
        first_ids.push(id);
    }

    client1.disconnect().await.unwrap();

    // Reconnect and send more messages
    let client2 = MqttClient::with_options(options);
    client2.connect(broker.address()).await.unwrap();

    let mut second_ids = Vec::new();
    for i in 5..10 {
        let id = client2
            .publish_qos1("test/pid", format!("Message {i}"))
            .await
            .unwrap();
        second_ids.push(id);
    }

    // With clean disconnection, packet IDs can be reused
    // This is normal behavior as the previous IDs were acknowledged
    println!("First session IDs: {first_ids:?}");
    println!("Second session IDs: {second_ids:?}");

    client2.disconnect().await.unwrap();
}

#[tokio::test]
async fn test_inflight_message_persistence() {
    // Start test broker
    let broker = TestBroker::start().await;

    // Test that in-flight QoS 1/2 messages are retransmitted after reconnection
    let pub_client_id = "inflight-pub";
    let sub_client_id = "inflight-sub";

    // Set up subscriber
    let sub_client =
        MqttClient::with_options(ConnectOptions::new(sub_client_id).with_clean_start(false));
    sub_client.connect(broker.address()).await.unwrap();

    let received = Arc::new(AtomicU32::new(0));
    let received_clone = received.clone();

    sub_client
        .subscribe_with_options(
            "test/inflight",
            mqtt5::SubscribeOptions {
                qos: QoS::AtLeastOnce,
                ..Default::default()
            },
            move |_| {
                received_clone.fetch_add(1, Ordering::Relaxed);
            },
        )
        .await
        .unwrap();

    // Publisher sends messages
    let pub_client =
        MqttClient::with_options(ConnectOptions::new(pub_client_id).with_clean_start(false));
    pub_client.connect(broker.address()).await.unwrap();

    // Send QoS 1 messages rapidly then disconnect
    // Some might still be in-flight
    for i in 0..10 {
        let _ = pub_client
            .publish_qos1("test/inflight", format!("Msg {i}"))
            .await;
    }

    // Quick disconnect might leave some messages in-flight
    pub_client.disconnect().await.unwrap();

    // Wait a bit
    sleep(Duration::from_millis(500)).await;

    let initial_count = received.load(Ordering::Relaxed);
    println!("Initially received: {initial_count} messages");

    // Reconnect publisher - any in-flight messages should be retransmitted
    let pub_client2 =
        MqttClient::with_options(ConnectOptions::new(pub_client_id).with_clean_start(false));
    pub_client2.connect(broker.address()).await.unwrap();

    // Wait for potential retransmissions
    sleep(Duration::from_secs(1)).await;

    let final_count = received.load(Ordering::Relaxed);
    println!("Finally received: {final_count} messages");

    // Should eventually receive all messages
    assert!(
        final_count >= 10,
        "Should receive all messages including retransmissions"
    );

    pub_client2.disconnect().await.unwrap();
    sub_client.disconnect().await.unwrap();
}

#[tokio::test]
async fn test_qos2_outbound_inflight_resend_on_reconnect() {
    let broker = TestBroker::start().await;

    let pub_client = MqttClient::new("qos2-inflight-pub");
    let sub_client_id = "qos2-inflight-sub";

    let sub_client =
        MqttClient::with_options(ConnectOptions::new(sub_client_id).with_clean_start(false));
    sub_client.connect(broker.address()).await.unwrap();

    sub_client
        .subscribe_with_options(
            "test/qos2/inflight",
            mqtt5::SubscribeOptions {
                qos: QoS::ExactlyOnce,
                ..Default::default()
            },
            |_| {},
        )
        .await
        .unwrap();

    sub_client.disconnect().await.unwrap();

    pub_client.connect(broker.address()).await.unwrap();
    for i in 0..3 {
        pub_client
            .publish_qos2("test/qos2/inflight", format!("inflight msg {i}"))
            .await
            .unwrap();
    }
    pub_client.disconnect().await.unwrap();

    let messages = Arc::new(std::sync::Mutex::new(Vec::new()));
    let messages_clone = messages.clone();

    let sub_client2 =
        MqttClient::with_options(ConnectOptions::new(sub_client_id).with_clean_start(false));

    let session = sub_client2
        .connect_with_options(
            broker.address(),
            ConnectOptions::new(sub_client_id).with_clean_start(false),
        )
        .await
        .unwrap();

    sub_client2
        .subscribe_with_options(
            "test/qos2/inflight",
            mqtt5::SubscribeOptions {
                qos: QoS::ExactlyOnce,
                ..Default::default()
            },
            move |msg| {
                messages_clone
                    .lock()
                    .unwrap()
                    .push(String::from_utf8_lossy(&msg.payload).to_string());
            },
        )
        .await
        .unwrap();

    sleep(Duration::from_secs(2)).await;

    {
        let msgs = messages.lock().unwrap();
        if session.session_present {
            assert!(
                !msgs.is_empty(),
                "should receive QoS2 messages after reconnect with session_present"
            );
            let mut unique = msgs.clone();
            unique.sort();
            unique.dedup();
            assert_eq!(
                msgs.len(),
                unique.len(),
                "QoS2 should not produce duplicates"
            );
        }
    }

    match sub_client2.disconnect().await {
        Ok(()) | Err(mqtt5::MqttError::NotConnected) => {}
        Err(e) => panic!("unexpected disconnect error: {e}"),
    }
}

#[tokio::test]
async fn test_clean_start_clears_inflight_state() {
    let broker = TestBroker::start().await;

    let pub_client = MqttClient::new("clean-inflight-pub");
    let sub_client_id = "clean-inflight-sub";

    let sub_client =
        MqttClient::with_options(ConnectOptions::new(sub_client_id).with_clean_start(false));
    sub_client.connect(broker.address()).await.unwrap();

    sub_client
        .subscribe_with_options(
            "test/clean/inflight",
            mqtt5::SubscribeOptions {
                qos: QoS::ExactlyOnce,
                ..Default::default()
            },
            |_| {},
        )
        .await
        .unwrap();

    sub_client.disconnect().await.unwrap();

    pub_client.connect(broker.address()).await.unwrap();
    for i in 0..3 {
        pub_client
            .publish_qos2("test/clean/inflight", format!("clean msg {i}"))
            .await
            .unwrap();
    }
    pub_client.disconnect().await.unwrap();

    let received = Arc::new(AtomicU32::new(0));
    let received_clone = received.clone();

    let sub_client2 =
        MqttClient::with_options(ConnectOptions::new(sub_client_id).with_clean_start(true));

    let session = sub_client2
        .connect_with_options(
            broker.address(),
            ConnectOptions::new(sub_client_id).with_clean_start(true),
        )
        .await
        .unwrap();

    assert!(
        !session.session_present,
        "clean_start=true should not have session_present"
    );

    sub_client2
        .subscribe_with_options(
            "test/clean/inflight",
            mqtt5::SubscribeOptions {
                qos: QoS::ExactlyOnce,
                ..Default::default()
            },
            move |_| {
                received_clone.fetch_add(1, Ordering::Relaxed);
            },
        )
        .await
        .unwrap();

    sleep(Duration::from_millis(500)).await;

    assert_eq!(
        received.load(Ordering::Relaxed),
        0,
        "clean_start=true should not deliver old queued or inflight messages"
    );

    sub_client2.disconnect().await.unwrap();
}