@@ -46,7 +46,11 @@ fn init_logs(is_simple: bool) -> Result<sdklogs::LoggerProvider> {
4646 Ok ( logger_provider)
4747}
4848
49- async fn logs_tokio_helper ( is_simple : bool , log_send_outside_rt : bool ) -> Result < ( ) > {
49+ async fn logs_tokio_helper (
50+ is_simple : bool ,
51+ log_send_outside_rt : bool ,
52+ current_thread : bool ,
53+ ) -> Result < ( ) > {
5054 use crate :: { assert_logs_results_contains, init_logs} ;
5155 test_utils:: start_collector_container ( ) . await ?;
5256
@@ -76,8 +80,15 @@ async fn logs_tokio_helper(is_simple: bool, log_send_outside_rt: bool) -> Result
7680 info ! ( target: "my-target" , uuid = expected_uuid. as_str( ) , "hello from {}. My price is {}." , "banana" , 2.99 ) ;
7781 }
7882 }
79- let _ = logger_provider. shutdown ( ) ;
80- tokio:: time:: sleep ( Duration :: from_secs ( 5 ) ) . await ;
83+ if current_thread {
84+ let _res = tokio:: runtime:: Handle :: current ( )
85+ . spawn_blocking ( move || logger_provider. shutdown ( ) )
86+ . await
87+ . unwrap ( ) ;
88+ } else {
89+ let _ = logger_provider. shutdown ( ) ;
90+ }
91+ tokio:: time:: sleep ( Duration :: from_secs ( 2 ) ) . await ;
8192 assert_logs_results_contains ( test_utils:: LOGS_FILE , expected_uuid. as_str ( ) ) ?;
8293 Ok ( ( ) )
8394}
@@ -115,8 +126,7 @@ fn logs_non_tokio_helper(is_simple: bool, init_logs_inside_rt: bool) -> Result<(
115126 ) ;
116127 }
117128
118- let _ = logger_provider. shutdown ( ) ;
119- std:: thread:: sleep ( Duration :: from_secs ( 5 ) ) ;
129+ std:: thread:: sleep ( Duration :: from_secs ( 2 ) ) ;
120130 assert_logs_results_contains ( test_utils:: LOGS_FILE , expected_uuid. as_str ( ) ) ?;
121131 Ok ( ( ) )
122132}
@@ -175,7 +185,7 @@ mod logtests {
175185 #[ tokio:: test( flavor = "multi_thread" , worker_threads = 4 ) ]
176186 #[ cfg( any( feature = "tonic-client" , feature = "reqwest-blocking-client" ) ) ]
177187 pub async fn logs_batch_tokio_multi_thread ( ) -> Result < ( ) > {
178- logs_tokio_helper ( false , false ) . await
188+ logs_tokio_helper ( false , false , false ) . await
179189 }
180190
181191 // logger initialization - Inside RT
@@ -185,7 +195,7 @@ mod logtests {
185195 #[ tokio:: test( flavor = "multi_thread" , worker_threads = 1 ) ]
186196 #[ cfg( any( feature = "tonic-client" , feature = "reqwest-blocking-client" ) ) ]
187197 pub async fn logs_batch_tokio_multi_with_one_worker ( ) -> Result < ( ) > {
188- logs_tokio_helper ( false , false ) . await
198+ logs_tokio_helper ( false , false , false ) . await
189199 }
190200
191201 // logger initialization - Inside RT
@@ -195,7 +205,7 @@ mod logtests {
195205 #[ tokio:: test( flavor = "current_thread" ) ]
196206 #[ cfg( any( feature = "tonic-client" , feature = "reqwest-blocking-client" ) ) ]
197207 pub async fn logs_batch_tokio_current ( ) -> Result < ( ) > {
198- logs_tokio_helper ( false , false ) . await
208+ logs_tokio_helper ( false , false , true ) . await
199209 }
200210
201211 // logger initialization - Inside RT
@@ -205,7 +215,7 @@ mod logtests {
205215 #[ tokio:: test( flavor = "multi_thread" , worker_threads = 4 ) ]
206216 #[ cfg( any( feature = "tonic-client" , feature = "reqwest-blocking-client" ) ) ]
207217 pub async fn logs_batch_tokio_log_outside_rt_multi_thread ( ) -> Result < ( ) > {
208- logs_tokio_helper ( false , true ) . await
218+ logs_tokio_helper ( false , true , false ) . await
209219 }
210220
211221 // logger initialization - Inside RT
@@ -215,7 +225,7 @@ mod logtests {
215225 #[ tokio:: test( flavor = "multi_thread" , worker_threads = 1 ) ]
216226 #[ cfg( any( feature = "tonic-client" , feature = "reqwest-blocking-client" ) ) ]
217227 pub async fn logs_batch_tokio_log_outside_rt_multi_with_one_worker ( ) -> Result < ( ) > {
218- logs_tokio_helper ( false , true ) . await
228+ logs_tokio_helper ( false , true , false ) . await
219229 }
220230
221231 // logger initialization - Inside RT
@@ -225,7 +235,7 @@ mod logtests {
225235 #[ tokio:: test( flavor = "current_thread" ) ]
226236 #[ cfg( any( feature = "tonic-client" , feature = "reqwest-blocking-client" ) ) ]
227237 pub async fn logs_batch_tokio_log_outside_rt_current_thread ( ) -> Result < ( ) > {
228- logs_tokio_helper ( false , true ) . await
238+ logs_tokio_helper ( false , true , true ) . await
229239 }
230240
231241 // logger initialization - Inside RT
@@ -310,7 +320,7 @@ mod logtests {
310320 #[ tokio:: test( flavor = "multi_thread" , worker_threads = 4 ) ]
311321 #[ cfg( feature = "reqwest-blocking-client" ) ]
312322 pub async fn logs_simple_tokio_multi_thread ( ) -> Result < ( ) > {
313- logs_tokio_helper ( true , false ) . await
323+ logs_tokio_helper ( true , false , false ) . await
314324 }
315325
316326 // logger initialization - Inside RT
@@ -324,7 +334,7 @@ mod logtests {
324334 feature = "hyper-client"
325335 ) ) ]
326336 pub async fn logs_simple_tokio_multi_thread ( ) -> Result < ( ) > {
327- logs_tokio_helper ( true , false ) . await
337+ logs_tokio_helper ( true , false , false ) . await
328338 }
329339
330340 // logger initialization - Inside RT
@@ -338,7 +348,7 @@ mod logtests {
338348 feature = "hyper-client"
339349 ) ) ]
340350 pub async fn logs_simple_tokio_multi_with_one_worker ( ) -> Result < ( ) > {
341- logs_tokio_helper ( true , false ) . await
351+ logs_tokio_helper ( true , false , false ) . await
342352 }
343353
344354 // logger initialization - Inside RT
@@ -353,7 +363,7 @@ mod logtests {
353363 feature = "hyper-client"
354364 ) ) ]
355365 pub async fn logs_simple_tokio_current ( ) -> Result < ( ) > {
356- logs_tokio_helper ( true , false ) . await
366+ logs_tokio_helper ( true , false , false ) . await
357367 }
358368}
359369///
0 commit comments