Skip to content

Commit eee300c

Browse files
authored
Revert "tests: Use tracing::subscriber::DefaultGuard to set subscriber (#8023)" (#8379)
This reverts commit aa0f784.
1 parent 93191f6 commit eee300c

File tree

5 files changed

+9
-19
lines changed

5 files changed

+9
-19
lines changed

src/tests/dump_db.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crates_io_test_db::TestDatabase;
33

44
#[test]
55
fn dump_db_and_reimport_dump() {
6-
let _guard = crates_io::util::tracing::init_for_test();
6+
crates_io::util::tracing::init_for_test();
77

88
let db_one = TestDatabase::new();
99

src/tests/util/test_app.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,8 @@ use oauth2::{ClientId, ClientSecret};
2323
use std::collections::HashSet;
2424
use std::{rc::Rc, sync::Arc, time::Duration};
2525
use tokio::runtime::Runtime;
26-
use tracing::subscriber::DefaultGuard;
2726

2827
struct TestAppInner {
29-
#[allow(dead_code)]
30-
tracing_guard: DefaultGuard,
31-
3228
pub runtime: Runtime,
3329

3430
app: Arc<App>,
@@ -81,10 +77,9 @@ pub struct TestApp(Rc<TestAppInner>);
8177
impl TestApp {
8278
/// Initialize an application with an `Uploader` that panics
8379
pub fn init() -> TestAppBuilder {
84-
let tracing_guard = crates_io::util::tracing::init_for_test();
80+
crates_io::util::tracing::init_for_test();
8581

8682
TestAppBuilder {
87-
tracing_guard,
8883
config: simple_config(),
8984
index: None,
9085
build_job_runner: false,
@@ -210,7 +205,6 @@ impl TestApp {
210205
}
211206

212207
pub struct TestAppBuilder {
213-
tracing_guard: DefaultGuard,
214208
config: config::Server,
215209
index: Option<UpstreamIndex>,
216210
build_job_runner: bool,
@@ -297,7 +291,6 @@ impl TestAppBuilder {
297291
};
298292

299293
let test_app_inner = TestAppInner {
300-
tracing_guard: self.tracing_guard,
301294
runtime,
302295
app,
303296
test_database,

src/util/tracing.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use sentry::integrations::tracing::EventFilter;
2-
use tracing::subscriber::DefaultGuard;
32
use tracing::Level;
43
use tracing::Metadata;
54
use tracing_subscriber::filter::LevelFilter;
@@ -47,17 +46,15 @@ pub fn event_filter(metadata: &Metadata<'_>) -> EventFilter {
4746
}
4847

4948
/// Initializes the `tracing` logging framework for usage in tests.
50-
pub fn init_for_test() -> DefaultGuard {
49+
pub fn init_for_test() {
5150
let env_filter = EnvFilter::builder()
5251
.with_default_directive(LevelFilter::INFO.into())
5352
.from_env_lossy();
5453

55-
let subscriber = tracing_subscriber::fmt()
54+
let _ = tracing_subscriber::fmt()
5655
.compact()
5756
.with_env_filter(env_filter)
5857
.without_time()
5958
.with_test_writer()
60-
.finish();
61-
62-
tracing::subscriber::set_default(subscriber)
59+
.try_init();
6360
}

src/worker/jobs/downloads/process_log.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ mod tests {
395395

396396
#[tokio::test]
397397
async fn test_process_cdn_log() {
398-
let _guard = crate::util::tracing::init_for_test();
398+
crate::util::tracing::init_for_test();
399399

400400
let test_database = TestDatabase::new();
401401
let db_pool = build_connection_pool(test_database.url());

src/worker/jobs/downloads/queue/job.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ mod tests {
233233

234234
#[tokio::test]
235235
async fn test_process_cdn_log_queue() {
236-
let _guard = crate::util::tracing::init_for_test();
236+
crate::util::tracing::init_for_test();
237237

238238
let mut queue = Box::new(MockSqsQueue::new());
239239
queue
@@ -263,7 +263,7 @@ mod tests {
263263

264264
#[tokio::test]
265265
async fn test_process_cdn_log_queue_multi_page() {
266-
let _guard = crate::util::tracing::init_for_test();
266+
crate::util::tracing::init_for_test();
267267

268268
let mut queue = Box::new(MockSqsQueue::new());
269269
queue
@@ -323,7 +323,7 @@ mod tests {
323323

324324
#[tokio::test]
325325
async fn test_process_cdn_log_queue_parse_error() {
326-
let _guard = crate::util::tracing::init_for_test();
326+
crate::util::tracing::init_for_test();
327327

328328
let mut queue = Box::new(MockSqsQueue::new());
329329
queue

0 commit comments

Comments
 (0)