@@ -299,132 +299,6 @@ async fn testing_an_mqtt_client_without_mqtt() -> Result<(), anyhow::Error> {
299
299
Ok ( ( ) )
300
300
}
301
301
302
- #[ tokio:: test]
303
- async fn creating_a_session ( ) -> Result < ( ) , anyhow:: Error > {
304
- // Given an MQTT broker
305
- let broker = mqtt_tests:: test_mqtt_broker ( ) ;
306
- let mqtt_config = Config :: default ( ) . with_port ( broker. port ) ;
307
-
308
- // Given an MQTT config with a well-known session name
309
- let session_name = uniquify ! ( "my-session-name" ) ;
310
- let topic = uniquify ! ( "my/topic" ) ;
311
- let mqtt_config = mqtt_config
312
- . with_session_name ( session_name)
313
- . with_subscriptions ( topic. try_into ( ) ?) ;
314
-
315
- // This config can be created to initialize an MQTT session
316
- init_session ( & mqtt_config) . await ?;
317
-
318
- // Any messages published on that topic
319
- broker
320
- . publish ( topic, "1st msg sent before a first connection" )
321
- . await ?;
322
- broker
323
- . publish ( topic, "2nd msg sent before a first connection" )
324
- . await ?;
325
- broker
326
- . publish ( topic, "3rd msg sent before a first connection" )
327
- . await ?;
328
-
329
- // Will be received by the client with the same session name even for its first connection
330
- let mut con = Connection :: new ( & mqtt_config) . await ?;
331
-
332
- assert_eq ! (
333
- MaybeMessage :: Next ( message( topic, "1st msg sent before a first connection" ) ) ,
334
- next_message( & mut con. received) . await
335
- ) ;
336
- assert_eq ! (
337
- MaybeMessage :: Next ( message( topic, "2nd msg sent before a first connection" ) ) ,
338
- next_message( & mut con. received) . await
339
- ) ;
340
- assert_eq ! (
341
- MaybeMessage :: Next ( message( topic, "3rd msg sent before a first connection" ) ) ,
342
- next_message( & mut con. received) . await
343
- ) ;
344
-
345
- Ok ( ( ) )
346
- }
347
-
348
- #[ tokio:: test]
349
- async fn a_session_must_have_a_name ( ) {
350
- let broker = mqtt_tests:: test_mqtt_broker ( ) ;
351
- let mqtt_config = Config :: default ( ) . with_port ( broker. port ) ;
352
-
353
- let result = init_session ( & mqtt_config) . await ;
354
- assert ! ( result. is_err( ) ) ;
355
- assert ! ( result. unwrap_err( ) . to_string( ) . contains( "Invalid session" ) ) ;
356
- }
357
-
358
- #[ tokio:: test]
359
- async fn a_named_session_must_not_set_clean_session ( ) {
360
- let broker = mqtt_tests:: test_mqtt_broker ( ) ;
361
- let mqtt_config = Config :: default ( )
362
- . with_port ( broker. port )
363
- . with_session_name ( uniquify ! ( "useless name" ) )
364
- . with_clean_session ( true ) ;
365
-
366
- let result = init_session ( & mqtt_config) . await ;
367
- assert ! ( result. is_err( ) ) ;
368
- assert ! ( result. unwrap_err( ) . to_string( ) . contains( "Invalid session" ) ) ;
369
- }
370
-
371
- #[ tokio:: test]
372
- async fn cleaning_a_session ( ) -> Result < ( ) , anyhow:: Error > {
373
- // Given an MQTT broker
374
- let broker = mqtt_tests:: test_mqtt_broker ( ) ;
375
- let mqtt_config = Config :: default ( ) . with_port ( broker. port ) ;
376
-
377
- // Given an MQTT config with a well-known session name
378
- let session_name = uniquify ! ( "a-session-name" ) ;
379
- let topic = uniquify ! ( "a/topic" ) ;
380
- let mqtt_config = mqtt_config
381
- . with_session_name ( session_name)
382
- . with_subscriptions ( topic. try_into ( ) ?) ;
383
-
384
- // The session being initialized
385
- init_session ( & mqtt_config) . await ?;
386
-
387
- // And some messages published
388
- broker
389
- . publish ( topic, "A fst msg published before clean" )
390
- . await ?;
391
- broker
392
- . publish ( topic, "A 2nd msg published before clean" )
393
- . await ?;
394
-
395
- // Then we clean the session
396
- {
397
- // One just needs a config with the same session name.
398
- // Subscriptions can be given - but this not required: any previous subscriptions will be cleared.
399
- let mqtt_config = Config :: default ( )
400
- . with_port ( broker. port )
401
- . with_session_name ( session_name) ;
402
- clear_session ( & mqtt_config) . await ?;
403
- }
404
-
405
- // And publish more messages
406
- broker
407
- . publish ( topic, "A 3nd msg published after clean" )
408
- . await ?;
409
-
410
- // Then no messages will be received by the client with the same session name
411
- let mut con = Connection :: new ( & mqtt_config) . await ?;
412
-
413
- assert_eq ! ( MaybeMessage :: Timeout , next_message( & mut con. received) . await ) ;
414
-
415
- Ok ( ( ) )
416
- }
417
-
418
- #[ tokio:: test]
419
- async fn to_be_cleared_a_session_must_have_a_name ( ) {
420
- let broker = mqtt_tests:: test_mqtt_broker ( ) ;
421
- let mqtt_config = Config :: default ( ) . with_port ( broker. port ) ;
422
-
423
- let result = clear_session ( & mqtt_config) . await ;
424
- assert ! ( result. is_err( ) ) ;
425
- assert ! ( result. unwrap_err( ) . to_string( ) . contains( "Invalid session" ) ) ;
426
- }
427
-
428
302
#[ tokio:: test]
429
303
async fn ensure_that_all_messages_are_sent_before_disconnect ( ) -> Result < ( ) , anyhow:: Error > {
430
304
let broker = mqtt_tests:: test_mqtt_broker ( ) ;
0 commit comments