@@ -18,9 +18,11 @@ use std::time::Duration;
1818
1919use async_channel:: bounded;
2020use databend_common_base:: base:: tokio;
21+ use databend_common_base:: base:: GlobalInstance ;
2122use databend_common_exception:: Result ;
2223use databend_common_tracing:: convert_to_batch;
2324use databend_common_tracing:: Config ;
25+ use databend_common_tracing:: GlobalLogger ;
2426use databend_common_tracing:: LogMessage ;
2527use databend_common_tracing:: RemoteLog ;
2628use databend_common_tracing:: RemoteLogBuffer ;
@@ -103,17 +105,18 @@ async fn test_buffer_flush_with_buffer_limit() -> Result<()> {
103105 Ok ( ( ) )
104106}
105107
106- #[ tokio:: test( flavor = "multi_thread" , worker_threads = 1 ) ]
107- async fn test_buffer_flush_with_buffer_interval ( ) -> Result < ( ) > {
108+ #[ test]
109+ fn test_buffer_flush_with_buffer_interval ( ) -> Result < ( ) > {
110+ init_global_logger ( ) ?;
108111 let ( tx, rx) = bounded ( 10 ) ;
109112 let interval = Duration :: from_secs ( 1 ) . as_micros ( ) as u64 ;
110113 let buffer = Arc :: new ( RemoteLogBuffer :: new ( tx. clone ( ) , interval) ) ;
111114 for _i in 0 ..5 {
112115 buffer. log ( get_remote_log_elements ( ) ) ?
113116 }
114- tokio :: time :: sleep ( Duration :: from_secs ( 1 ) ) . await ;
117+ std :: thread :: sleep ( Duration :: from_secs ( 1 ) ) ;
115118 buffer. log ( get_remote_log_elements ( ) ) ?;
116- let res = rx. recv ( ) . await . unwrap ( ) ;
119+ let res = rx. recv_blocking ( ) . unwrap ( ) ;
117120 if let LogMessage :: Flush ( elements) = res {
118121 assert_eq ! ( elements. len( ) , 6 ) ;
119122 }
@@ -152,3 +155,11 @@ async fn test_do_flush() -> Result<()> {
152155
153156 Ok ( ( ) )
154157}
158+
159+ fn init_global_logger ( ) -> Result < ( ) > {
160+ let thread = std:: thread:: current ( ) ;
161+ GlobalInstance :: init_testing ( thread. name ( ) . unwrap ( ) ) ;
162+ let instance = GlobalLogger :: dummy ( ) ;
163+ GlobalInstance :: set ( instance) ;
164+ Ok ( ( ) )
165+ }
0 commit comments