@@ -572,36 +572,21 @@ mod tests {
572572 use futures:: { FutureExt , StreamExt } ;
573573 use tokio:: time:: timeout;
574574 use tower:: ServiceExt ;
575- use zenoh:: { bytes:: Encoding , sample:: SampleKind , Config , Session , Wait } ;
575+ use zenoh:: { bytes:: Encoding , sample:: SampleKind , Session , Wait } ;
576+ use zenoh_test:: TestSessions ;
576577
577578 use crate :: app;
578579
579- const TEST_PORTS : [ u16 ; 3 ] = [ 42000 , 42001 , 42002 ] ;
580-
581- async fn setup ( port : u16 ) -> ( Session , Session ) {
582- let mut config1 = Config :: default ( ) ;
583- config1. scouting . multicast . set_enabled ( Some ( false ) ) . unwrap ( ) ;
584- config1
585- . listen
586- . endpoints
587- . set ( vec ! [ format!( "tcp/127.0.0.1:{}" , port) . parse( ) . unwrap( ) ] )
588- . unwrap ( ) ;
589-
590- let mut config2 = Config :: default ( ) ;
591- config2. scouting . multicast . set_enabled ( Some ( false ) ) . unwrap ( ) ;
592- config2
593- . connect
594- . endpoints
595- . set ( vec ! [ format!( "tcp/127.0.0.1:{}" , port) . parse( ) . unwrap( ) ] )
596- . unwrap ( ) ;
597- let ( s1, s2) = tokio:: try_join!( zenoh:: open( config1) , zenoh:: open( config2) ) . unwrap ( ) ;
580+ async fn setup ( ) -> ( TestSessions , Session , Session ) {
581+ let mut test_sessions = TestSessions :: new ( ) ;
582+ let ( s1, s2) = test_sessions. open_pairs ( ) . await ;
598583 tokio:: time:: sleep ( Duration :: from_secs ( 1 ) ) . await ;
599- ( s1, s2)
584+ ( test_sessions , s1, s2)
600585 }
601586
602587 #[ tokio:: test( flavor = "multi_thread" , worker_threads = 4 ) ]
603588 async fn publish ( ) {
604- let ( pub_session, sub_session) = setup ( TEST_PORTS [ 0 ] ) . await ;
589+ let ( mut test_sessions , pub_session, sub_session) = setup ( ) . await ;
605590 let subscriber = sub_session. declare_subscriber ( "test/**" ) . await . unwrap ( ) ;
606591 tokio:: time:: sleep ( Duration :: from_secs ( 1 ) ) . await ;
607592 for method in [ Method :: PUT , Method :: PATCH ] {
@@ -639,11 +624,13 @@ mod tests {
639624 let sample = subscriber. try_recv ( ) . unwrap ( ) . unwrap ( ) ;
640625 assert_eq ! ( sample. kind( ) , SampleKind :: Delete ) ;
641626 assert_eq ! ( sample. key_expr( ) . as_str( ) , "test/publish" ) ;
627+
628+ test_sessions. close ( ) . await ;
642629 }
643630
644631 #[ tokio:: test( flavor = "multi_thread" , worker_threads = 4 ) ]
645632 async fn subscribe ( ) {
646- let ( pub_session, sub_session) = setup ( TEST_PORTS [ 1 ] ) . await ;
633+ let ( mut test_sessions , pub_session, sub_session) = setup ( ) . await ;
647634 let response = app ( sub_session. clone ( ) )
648635 . oneshot (
649636 Request :: builder ( )
@@ -685,11 +672,13 @@ mod tests {
685672 } ) ,
686673 ) ;
687674 }
675+
676+ test_sessions. close ( ) . await ;
688677 }
689678
690679 #[ tokio:: test( flavor = "multi_thread" , worker_threads = 4 ) ]
691680 async fn query ( ) {
692- let ( get_session, queryable_session) = setup ( TEST_PORTS [ 2 ] ) . await ;
681+ let ( mut test_sessions , get_session, queryable_session) = setup ( ) . await ;
693682 let _queryable = queryable_session
694683 . declare_queryable ( "test/**" )
695684 . callback ( |q| {
@@ -746,5 +735,7 @@ mod tests {
746735 . unwrap ( ) ;
747736 check ( body) ;
748737 }
738+
739+ test_sessions. close ( ) . await ;
749740 }
750741}
0 commit comments