From 73f4d7e453c74e2c620d5fa1f1d5d1fe225cef12 Mon Sep 17 00:00:00 2001 From: Igor Katson Date: Wed, 21 Aug 2024 13:45:20 +0100 Subject: [PATCH] more test logs --- crates/librqbit/src/tests/e2e.rs | 5 +++-- crates/librqbit/src/tests/e2e_stream.rs | 6 ++++-- crates/librqbit/src/tests/test_util.rs | 7 +++++++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/crates/librqbit/src/tests/e2e.rs b/crates/librqbit/src/tests/e2e.rs index e39d316..ee6f5db 100644 --- a/crates/librqbit/src/tests/e2e.rs +++ b/crates/librqbit/src/tests/e2e.rs @@ -15,7 +15,8 @@ use tracing::{error, error_span, info, Instrument}; use crate::{ create_torrent, tests::test_util::{ - create_default_random_dir_with_torrents, spawn_debug_server, TestPeerMetadata, + create_default_random_dir_with_torrents, setup_test_logging, spawn_debug_server, + TestPeerMetadata, }, AddTorrentOptions, AddTorrentResponse, Session, SessionOptions, SessionPersistenceConfig, }; @@ -34,7 +35,7 @@ async fn test_e2e_download() { } async fn _test_e2e_download() { - let _ = tracing_subscriber::fmt::try_init(); + setup_test_logging(); match crate::try_increase_nofile_limit() { Ok(limit) => info!(limit, "increased ulimit"), Err(e) => error!(error=?e, "error increasing ulimit"), diff --git a/crates/librqbit/src/tests/e2e_stream.rs b/crates/librqbit/src/tests/e2e_stream.rs index 61ec741..4af90c1 100644 --- a/crates/librqbit/src/tests/e2e_stream.rs +++ b/crates/librqbit/src/tests/e2e_stream.rs @@ -6,12 +6,15 @@ use tokio::{io::AsyncReadExt, time::timeout}; use tracing::info; use crate::{ - create_torrent, tests::test_util::TestPeerMetadata, AddTorrent, CreateTorrentOptions, Session, + create_torrent, + tests::test_util::{setup_test_logging, TestPeerMetadata}, + AddTorrent, CreateTorrentOptions, Session, }; use super::test_util::create_default_random_dir_with_torrents; async fn e2e_stream() -> anyhow::Result<()> { + setup_test_logging(); let files = create_default_random_dir_with_torrents(1, 8192, Some("test_e2e_stream")); let torrent = create_torrent( files.path(), @@ -113,6 +116,5 @@ async fn e2e_stream() -> anyhow::Result<()> { #[tokio::test(flavor = "multi_thread")] async fn test_e2e_stream() -> anyhow::Result<()> { - let _ = tracing_subscriber::fmt::try_init(); timeout(Duration::from_secs(10), e2e_stream()).await? } diff --git a/crates/librqbit/src/tests/test_util.rs b/crates/librqbit/src/tests/test_util.rs index ad1de10..4aac149 100644 --- a/crates/librqbit/src/tests/test_util.rs +++ b/crates/librqbit/src/tests/test_util.rs @@ -7,6 +7,13 @@ use rand::{thread_rng, Rng, RngCore, SeedableRng}; use tempfile::TempDir; use tracing::{debug, info}; +pub fn setup_test_logging() { + if let Err(_) = std::env::var("RUST_LOG") { + std::env::set_var("RUST_LOG", "debug"); + } + let _ = tracing_subscriber::fmt::try_init(); +} + pub fn create_new_file_with_random_content(path: &Path, mut size: usize) { let mut file = std::fs::OpenOptions::new() .create_new(true)