@@ -452,3 +452,50 @@ mod tests {
452452 assert ! ( tsc. is_outdated( ) . not( ) ) ;
453453 }
454454}
455+
456+ #[ cfg( all( test, not( target_family = "wasm" ) ) ) ]
457+ mod timed_tests {
458+ use std:: time:: Duration ;
459+
460+ use matrix_sdk_base:: { ThreadingSupport , sleep:: sleep} ;
461+ use matrix_sdk_test:: async_test;
462+ use tokio:: task:: yield_now;
463+
464+ use crate :: { client:: WeakClient , test_utils:: mocks:: MatrixMockServer } ;
465+
466+ #[ async_test]
467+ async fn test_issue_6573_client_can_drop_thread_subscriptions_task ( ) {
468+ let server = MatrixMockServer :: new ( ) . await ;
469+ server. mock_versions ( ) . with_thread_subscriptions ( ) . ok ( ) . mount ( ) . await ;
470+
471+ let client = server
472+ . client_builder ( )
473+ . no_server_versions ( )
474+ . on_builder ( |builder| {
475+ builder
476+ . with_threading_support ( ThreadingSupport :: Enabled { with_subscriptions : true } )
477+ } )
478+ . build ( )
479+ . await ;
480+
481+ let tsc = client. thread_subscription_catchup ( ) ;
482+
483+ // Wait for anything to start up.
484+ yield_now ( ) . await ;
485+
486+ // Ensure the task is running.
487+ assert ! ( tsc. _task. get( ) . is_some( ) ) ;
488+
489+ // Get a weak reference to the client.
490+ let weak_client = WeakClient :: from_client ( & client) ;
491+
492+ // Drop the client will drop the task.
493+ drop ( client) ;
494+
495+ // Wait for anything to shutdown.
496+ sleep ( Duration :: from_secs ( 2 ) ) . await ;
497+
498+ // The client has been dropped correctly.
499+ assert_eq ! ( weak_client. strong_count( ) , 0 ) ;
500+ }
501+ }
0 commit comments