File tree Expand file tree Collapse file tree 3 files changed +15
-5
lines changed Expand file tree Collapse file tree 3 files changed +15
-5
lines changed Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ use crates_io_test_db::TestDatabase;
3
3
4
4
#[ test]
5
5
fn dump_db_and_reimport_dump ( ) {
6
- crates_io:: util:: tracing:: init_for_test ( ) ;
6
+ let _guard = crates_io:: util:: tracing:: init_for_test ( ) ;
7
7
8
8
let db_one = TestDatabase :: new ( ) ;
9
9
Original file line number Diff line number Diff line change @@ -20,8 +20,12 @@ use oauth2::{ClientId, ClientSecret};
20
20
use std:: collections:: HashSet ;
21
21
use std:: { rc:: Rc , sync:: Arc , time:: Duration } ;
22
22
use tokio:: runtime:: Runtime ;
23
+ use tracing:: subscriber:: DefaultGuard ;
23
24
24
25
struct TestAppInner {
26
+ #[ allow( dead_code) ]
27
+ tracing_guard : DefaultGuard ,
28
+
25
29
pub runtime : Runtime ,
26
30
27
31
app : Arc < App > ,
@@ -74,9 +78,10 @@ pub struct TestApp(Rc<TestAppInner>);
74
78
impl TestApp {
75
79
/// Initialize an application with an `Uploader` that panics
76
80
pub fn init ( ) -> TestAppBuilder {
77
- crates_io:: util:: tracing:: init_for_test ( ) ;
81
+ let tracing_guard = crates_io:: util:: tracing:: init_for_test ( ) ;
78
82
79
83
TestAppBuilder {
84
+ tracing_guard,
80
85
config : simple_config ( ) ,
81
86
index : None ,
82
87
build_job_runner : false ,
@@ -202,6 +207,7 @@ impl TestApp {
202
207
}
203
208
204
209
pub struct TestAppBuilder {
210
+ tracing_guard : DefaultGuard ,
205
211
config : config:: Server ,
206
212
index : Option < UpstreamIndex > ,
207
213
build_job_runner : bool ,
@@ -286,6 +292,7 @@ impl TestAppBuilder {
286
292
} ;
287
293
288
294
let test_app_inner = TestAppInner {
295
+ tracing_guard : self . tracing_guard ,
289
296
runtime,
290
297
app,
291
298
test_database,
Original file line number Diff line number Diff line change 1
1
use sentry:: integrations:: tracing:: EventFilter ;
2
+ use tracing:: subscriber:: DefaultGuard ;
2
3
use tracing:: Level ;
3
4
use tracing:: Metadata ;
4
5
use tracing_subscriber:: filter:: LevelFilter ;
@@ -46,15 +47,17 @@ pub fn event_filter(metadata: &Metadata<'_>) -> EventFilter {
46
47
}
47
48
48
49
/// Initializes the `tracing` logging framework for usage in tests.
49
- pub fn init_for_test ( ) {
50
+ pub fn init_for_test ( ) -> DefaultGuard {
50
51
let env_filter = EnvFilter :: builder ( )
51
52
. with_default_directive ( LevelFilter :: INFO . into ( ) )
52
53
. from_env_lossy ( ) ;
53
54
54
- let _ = tracing_subscriber:: fmt ( )
55
+ let subscriber = tracing_subscriber:: fmt ( )
55
56
. compact ( )
56
57
. with_env_filter ( env_filter)
57
58
. without_time ( )
58
59
. with_test_writer ( )
59
- . try_init ( ) ;
60
+ . finish ( ) ;
61
+
62
+ tracing:: subscriber:: set_default ( subscriber)
60
63
}
You can’t perform that action at this time.
0 commit comments