diff --git a/examples/simple_torrent/src/main.rs b/examples/simple_torrent/src/main.rs index 0ed0e0483..87295d9a0 100644 --- a/examples/simple_torrent/src/main.rs +++ b/examples/simple_torrent/src/main.rs @@ -67,7 +67,10 @@ enum Setup { } pub fn tracing_stdout_init(filter: LevelFilter) { - let builder = tracing_subscriber::fmt().with_max_level(filter).with_ansi(true); + let builder = tracing_subscriber::fmt() + .with_max_level(filter) + .with_ansi(true) + .with_writer(std::io::stdout); builder.pretty().with_file(true).init(); diff --git a/packages/dht/examples/debug.rs b/packages/dht/examples/debug.rs index 2fbf58ee3..df7e3d5ad 100644 --- a/packages/dht/examples/debug.rs +++ b/packages/dht/examples/debug.rs @@ -51,7 +51,7 @@ impl HandshakerTrait for SimpleHandshaker { fn metadata(&mut self, (): Self::MetadataEnvelope) {} } -fn tracing_stdout_init(filter: LevelFilter) { +fn tracing_stderr_init(filter: LevelFilter) { let builder = tracing_subscriber::fmt().with_max_level(filter).with_ansi(true); builder.pretty().with_file(true).init(); @@ -62,7 +62,7 @@ fn tracing_stdout_init(filter: LevelFilter) { #[tokio::main] async fn main() { INIT.call_once(|| { - tracing_stdout_init(LevelFilter::INFO); + tracing_stderr_init(LevelFilter::INFO); }); let hash = InfoHash::from_bytes(b"My Unique Info Hash"); diff --git a/packages/disk/examples/add_torrent.rs b/packages/disk/examples/add_torrent.rs index 53befdcd5..46d000cb0 100644 --- a/packages/disk/examples/add_torrent.rs +++ b/packages/disk/examples/add_torrent.rs @@ -10,7 +10,7 @@ use tracing::level_filters::LevelFilter; static INIT: Once = Once::new(); -fn tracing_stdout_init(filter: LevelFilter) { +fn tracing_stderr_init(filter: LevelFilter) { let builder = tracing_subscriber::fmt().with_max_level(filter).with_ansi(true); builder.pretty().with_file(true).init(); @@ -21,7 +21,7 @@ fn tracing_stdout_init(filter: LevelFilter) { #[tokio::main] async fn main() { INIT.call_once(|| { - tracing_stdout_init(LevelFilter::INFO); + tracing_stderr_init(LevelFilter::INFO); }); tracing::info!("Utility For Allocating Disk Space For A Torrent File"); diff --git a/packages/disk/src/disk/manager.rs b/packages/disk/src/disk/manager.rs index 327dade3f..6b0355d61 100644 --- a/packages/disk/src/disk/manager.rs +++ b/packages/disk/src/disk/manager.rs @@ -185,7 +185,7 @@ where } fn start_send(self: std::pin::Pin<&mut Self>, item: IDiskMessage) -> Result<(), Self::Error> { - tracing::info!("Starting Send For DiskManagerSink With IDiskMessage"); + tracing::trace!("Starting Send For DiskManagerSink With IDiskMessage"); self.task_set .lock() .unwrap() @@ -269,7 +269,7 @@ impl Stream for DiskManagerStream { type Item = Result; fn poll_next(mut self: std::pin::Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { - tracing::info!("Polling DiskManagerStream For ODiskMessage"); + tracing::trace!("Polling DiskManagerStream For ODiskMessage"); match self.recv.poll_next_unpin(cx) { Poll::Ready(Some(msg)) => { diff --git a/packages/disk/tests/add_torrent.rs b/packages/disk/tests/add_torrent.rs index 3281dd877..72ad5d6f8 100644 --- a/packages/disk/tests/add_torrent.rs +++ b/packages/disk/tests/add_torrent.rs @@ -1,5 +1,5 @@ use common::{ - random_buffer, runtime_loop_with_timeout, tracing_stdout_init, InMemoryFileSystem, MultiFileDirectAccessor, DEFAULT_TIMEOUT, + random_buffer, runtime_loop_with_timeout, tracing_stderr_init, InMemoryFileSystem, MultiFileDirectAccessor, DEFAULT_TIMEOUT, INIT, }; use disk::{DiskManagerBuilder, FileSystem as _, IDiskMessage, ODiskMessage}; @@ -13,7 +13,7 @@ mod common; #[tokio::test] async fn positive_add_torrent() { INIT.call_once(|| { - tracing_stdout_init(LevelFilter::INFO); + tracing_stderr_init(LevelFilter::INFO); }); // Create some "files" as random bytes diff --git a/packages/disk/tests/common/mod.rs b/packages/disk/tests/common/mod.rs index 0da4db507..c089b85a8 100644 --- a/packages/disk/tests/common/mod.rs +++ b/packages/disk/tests/common/mod.rs @@ -21,8 +21,11 @@ pub const DEFAULT_TIMEOUT: Duration = Duration::from_millis(500); pub static INIT: Once = Once::new(); #[allow(dead_code)] -pub fn tracing_stdout_init(filter: LevelFilter) { - let builder = tracing_subscriber::fmt().with_max_level(filter).with_ansi(true); +pub fn tracing_stderr_init(filter: LevelFilter) { + let builder = tracing_subscriber::fmt() + .with_max_level(filter) + .with_ansi(true) + .with_writer(std::io::stderr); builder.pretty().with_file(true).init(); diff --git a/packages/disk/tests/complete_torrent.rs b/packages/disk/tests/complete_torrent.rs index 13ce603ce..d7ffcf172 100644 --- a/packages/disk/tests/complete_torrent.rs +++ b/packages/disk/tests/complete_torrent.rs @@ -1,5 +1,5 @@ use common::{ - random_buffer, runtime_loop_with_timeout, send_block, tracing_stdout_init, InMemoryFileSystem, MultiFileDirectAccessor, + random_buffer, runtime_loop_with_timeout, send_block, tracing_stderr_init, InMemoryFileSystem, MultiFileDirectAccessor, DEFAULT_TIMEOUT, INIT, }; use disk::{DiskManagerBuilder, IDiskMessage, ODiskMessage}; @@ -17,7 +17,7 @@ mod common; #[tokio::test] async fn positive_complete_torrent() { INIT.call_once(|| { - tracing_stdout_init(LevelFilter::DEBUG); + tracing_stderr_init(LevelFilter::INFO); }); let mut tasks = JoinSet::new(); @@ -60,7 +60,7 @@ async fn positive_complete_torrent() { b }; - tracing::warn!("send two blocks that are known to be good, then one bad block"); + tracing::debug!("send two blocks that are known to be good, then one bad block"); let send_one_bad_and_two_good = { let mut send = send.clone(); @@ -90,7 +90,7 @@ async fn positive_complete_torrent() { tasks.spawn(send_one_bad_and_two_good); - tracing::warn!("verify that piece 0 is bad, but piece 1 and 2 are good"); + tracing::debug!("verify that piece 0 is bad, but piece 1 and 2 are good"); let (recv, piece_zero_good, piece_one_good, piece_two_good) = runtime_loop_with_timeout( DEFAULT_TIMEOUT, @@ -142,7 +142,7 @@ async fn positive_complete_torrent() { assert!(tasks.is_empty(), "all the tasks should have finished now"); } - tracing::warn!("resend piece 0 with good blocks"); + tracing::debug!("resend piece 0 with good blocks"); let resend_with_good_blocks = { let mut send = send.clone(); @@ -158,7 +158,7 @@ async fn positive_complete_torrent() { tasks.spawn(resend_with_good_blocks); - tracing::warn!("verify that piece 0 is now good"); + tracing::debug!("verify that piece 0 is now good"); let piece_zero_good = runtime_loop_with_timeout( DEFAULT_TIMEOUT, diff --git a/packages/disk/tests/disk_manager_send_backpressure.rs b/packages/disk/tests/disk_manager_send_backpressure.rs index d58084fb6..9b5e3d55c 100644 --- a/packages/disk/tests/disk_manager_send_backpressure.rs +++ b/packages/disk/tests/disk_manager_send_backpressure.rs @@ -1,4 +1,4 @@ -use common::{random_buffer, tracing_stdout_init, InMemoryFileSystem, MultiFileDirectAccessor, DEFAULT_TIMEOUT, INIT}; +use common::{random_buffer, tracing_stderr_init, InMemoryFileSystem, MultiFileDirectAccessor, DEFAULT_TIMEOUT, INIT}; use disk::{DiskManagerBuilder, IDiskMessage}; use futures::{FutureExt, SinkExt as _, StreamExt as _}; use metainfo::{Metainfo, MetainfoBuilder, PieceLength}; @@ -9,7 +9,7 @@ mod common; #[tokio::test] async fn positive_disk_manager_send_backpressure() { INIT.call_once(|| { - tracing_stdout_init(LevelFilter::TRACE); + tracing_stderr_init(LevelFilter::INFO); }); // Create some "files" as random bytes diff --git a/packages/disk/tests/load_block.rs b/packages/disk/tests/load_block.rs index 0bbe9251a..5b877516a 100644 --- a/packages/disk/tests/load_block.rs +++ b/packages/disk/tests/load_block.rs @@ -1,5 +1,5 @@ use bytes::BytesMut; -use common::{random_buffer, tracing_stdout_init, InMemoryFileSystem, MultiFileDirectAccessor, INIT}; +use common::{random_buffer, tracing_stderr_init, InMemoryFileSystem, MultiFileDirectAccessor, INIT}; use disk::{Block, BlockMetadata, BlockMut, DiskManagerBuilder, IDiskMessage, ODiskMessage}; use futures::{SinkExt as _, StreamExt as _}; use metainfo::{Metainfo, MetainfoBuilder, PieceLength}; @@ -11,7 +11,7 @@ mod common; #[tokio::test] async fn positive_load_block() { INIT.call_once(|| { - tracing_stdout_init(LevelFilter::INFO); + tracing_stderr_init(LevelFilter::INFO); }); // Create some "files" as random bytes diff --git a/packages/disk/tests/process_block.rs b/packages/disk/tests/process_block.rs index 1394c382e..42906e7e2 100644 --- a/packages/disk/tests/process_block.rs +++ b/packages/disk/tests/process_block.rs @@ -1,6 +1,6 @@ use bytes::BytesMut; use common::{ - random_buffer, runtime_loop_with_timeout, tracing_stdout_init, InMemoryFileSystem, MultiFileDirectAccessor, DEFAULT_TIMEOUT, + random_buffer, runtime_loop_with_timeout, tracing_stderr_init, InMemoryFileSystem, MultiFileDirectAccessor, DEFAULT_TIMEOUT, INIT, }; use disk::{Block, BlockMetadata, DiskManagerBuilder, FileSystem, IDiskMessage, ODiskMessage}; @@ -13,7 +13,7 @@ mod common; #[tokio::test] async fn positive_process_block() { INIT.call_once(|| { - tracing_stdout_init(LevelFilter::INFO); + tracing_stderr_init(LevelFilter::INFO); }); // Create some "files" as random bytes diff --git a/packages/disk/tests/remove_torrent.rs b/packages/disk/tests/remove_torrent.rs index 6447d1af4..ec3606bff 100644 --- a/packages/disk/tests/remove_torrent.rs +++ b/packages/disk/tests/remove_torrent.rs @@ -1,6 +1,6 @@ use bytes::BytesMut; use common::{ - random_buffer, runtime_loop_with_timeout, tracing_stdout_init, InMemoryFileSystem, MultiFileDirectAccessor, DEFAULT_TIMEOUT, + random_buffer, runtime_loop_with_timeout, tracing_stderr_init, InMemoryFileSystem, MultiFileDirectAccessor, DEFAULT_TIMEOUT, INIT, }; use disk::{Block, BlockMetadata, DiskManagerBuilder, IDiskMessage, ODiskMessage}; @@ -13,7 +13,7 @@ mod common; #[tokio::test] async fn positive_remove_torrent() { INIT.call_once(|| { - tracing_stdout_init(LevelFilter::INFO); + tracing_stderr_init(LevelFilter::INFO); }); // Create some "files" as random bytes diff --git a/packages/disk/tests/resume_torrent.rs b/packages/disk/tests/resume_torrent.rs index 737b875ed..5fc09dc43 100644 --- a/packages/disk/tests/resume_torrent.rs +++ b/packages/disk/tests/resume_torrent.rs @@ -1,5 +1,5 @@ use common::{ - random_buffer, runtime_loop_with_timeout, send_block, tracing_stdout_init, InMemoryFileSystem, MultiFileDirectAccessor, + random_buffer, runtime_loop_with_timeout, send_block, tracing_stderr_init, InMemoryFileSystem, MultiFileDirectAccessor, DEFAULT_TIMEOUT, INIT, }; use disk::{DiskManagerBuilder, IDiskMessage, ODiskMessage}; @@ -13,7 +13,7 @@ mod common; #[tokio::test] async fn positive_complete_torrent() { INIT.call_once(|| { - tracing_stdout_init(LevelFilter::INFO); + tracing_stderr_init(LevelFilter::INFO); }); // Create some "files" as random bytes diff --git a/packages/handshake/src/bittorrent/framed.rs b/packages/handshake/src/bittorrent/framed.rs index 6320ea824..3b7e350a1 100644 --- a/packages/handshake/src/bittorrent/framed.rs +++ b/packages/handshake/src/bittorrent/framed.rs @@ -310,8 +310,11 @@ mod tests { pub static INIT: Once = Once::new(); - pub fn tracing_stdout_init(filter: LevelFilter) { - let builder = tracing_subscriber::fmt().with_max_level(filter).with_ansi(true); + pub fn tracing_stderr_init(filter: LevelFilter) { + let builder = tracing_subscriber::fmt() + .with_max_level(filter) + .with_ansi(true) + .with_writer(std::io::stderr); builder.pretty().with_file(true).init(); @@ -333,7 +336,7 @@ mod tests { #[tokio::test] async fn write_and_read_into_async_buffer() { INIT.call_once(|| { - tracing_stdout_init(LevelFilter::TRACE); + tracing_stderr_init(LevelFilter::INFO); }); let mut v = vec![0; 100]; @@ -360,7 +363,7 @@ mod tests { #[tokio::test] async fn positive_write_handshake_message() { INIT.call_once(|| { - tracing_stdout_init(LevelFilter::TRACE); + tracing_stderr_init(LevelFilter::INFO); }); let message = HandshakeMessage::from_parts(Protocol::BitTorrent, any_extensions(), any_info_hash(), any_peer_id()); @@ -380,7 +383,7 @@ mod tests { #[tokio::test] async fn positive_write_multiple_handshake_messages() { INIT.call_once(|| { - tracing_stdout_init(LevelFilter::TRACE); + tracing_stderr_init(LevelFilter::INFO); }); let message_one = HandshakeMessage::from_parts(Protocol::BitTorrent, any_extensions(), any_info_hash(), any_peer_id()); @@ -408,7 +411,7 @@ mod tests { #[tokio::test] async fn positive_read_handshake_message() { INIT.call_once(|| { - tracing_stdout_init(LevelFilter::TRACE); + tracing_stderr_init(LevelFilter::INFO); }); let exp_message = HandshakeMessage::from_parts(Protocol::BitTorrent, any_extensions(), any_info_hash(), any_peer_id()); @@ -436,7 +439,7 @@ mod tests { #[tokio::test] async fn positive_read_byte_after_handshake() { INIT.call_once(|| { - tracing_stdout_init(LevelFilter::TRACE); + tracing_stderr_init(LevelFilter::INFO); }); let exp_message = HandshakeMessage::from_parts(Protocol::BitTorrent, any_extensions(), any_info_hash(), any_peer_id()); @@ -465,7 +468,7 @@ mod tests { #[tokio::test] async fn positive_read_bytes_after_handshake() { INIT.call_once(|| { - tracing_stdout_init(LevelFilter::TRACE); + tracing_stderr_init(LevelFilter::INFO); }); let exp_message = HandshakeMessage::from_parts(Protocol::BitTorrent, any_extensions(), any_info_hash(), any_peer_id()); diff --git a/packages/handshake/tests/common/mod.rs b/packages/handshake/tests/common/mod.rs index 3b171bf56..c952d9cc5 100644 --- a/packages/handshake/tests/common/mod.rs +++ b/packages/handshake/tests/common/mod.rs @@ -15,8 +15,11 @@ pub enum TimeoutResult { } #[allow(dead_code)] -pub fn tracing_stdout_init(filter: LevelFilter) { - let builder = tracing_subscriber::fmt().with_max_level(filter).with_ansi(true); +pub fn tracing_stderr_init(filter: LevelFilter) { + let builder = tracing_subscriber::fmt() + .with_max_level(filter) + .with_ansi(true) + .with_writer(std::io::stderr); builder.pretty().with_file(true).init(); diff --git a/packages/handshake/tests/test_byte_after_handshake.rs b/packages/handshake/tests/test_byte_after_handshake.rs index dccfe7ad8..4d82773b5 100644 --- a/packages/handshake/tests/test_byte_after_handshake.rs +++ b/packages/handshake/tests/test_byte_after_handshake.rs @@ -1,7 +1,7 @@ use std::io::{Read, Write}; use std::net::TcpStream; -use common::{tracing_stdout_init, INIT}; +use common::{tracing_stderr_init, INIT}; use futures::stream::StreamExt; use handshake::transports::TcpTransport; use handshake::{DiscoveryInfo, HandshakerBuilder}; @@ -14,7 +14,7 @@ mod common; #[tokio::test] async fn positive_recover_bytes() { INIT.call_once(|| { - tracing_stdout_init(LevelFilter::TRACE); + tracing_stderr_init(LevelFilter::INFO); }); let mut handshaker_one_addr = "127.0.0.1:0".parse().unwrap(); diff --git a/packages/handshake/tests/test_bytes_after_handshake.rs b/packages/handshake/tests/test_bytes_after_handshake.rs index ba6c07408..3ab58a1f2 100644 --- a/packages/handshake/tests/test_bytes_after_handshake.rs +++ b/packages/handshake/tests/test_bytes_after_handshake.rs @@ -1,7 +1,7 @@ use std::io::{Read, Write}; use std::net::{IpAddr, Ipv4Addr, SocketAddr, TcpStream}; -use common::{tracing_stdout_init, INIT}; +use common::{tracing_stderr_init, INIT}; use futures::stream::StreamExt; use handshake::transports::TcpTransport; use handshake::{DiscoveryInfo, HandshakerBuilder}; @@ -14,7 +14,7 @@ mod common; #[tokio::test] async fn positive_recover_bytes() { INIT.call_once(|| { - tracing_stdout_init(LevelFilter::TRACE); + tracing_stderr_init(LevelFilter::INFO); }); let mut handshaker_one_addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::UNSPECIFIED), 0); diff --git a/packages/handshake/tests/test_connect.rs b/packages/handshake/tests/test_connect.rs index 55844ac8a..a430289fa 100644 --- a/packages/handshake/tests/test_connect.rs +++ b/packages/handshake/tests/test_connect.rs @@ -1,4 +1,4 @@ -use common::{tracing_stdout_init, INIT}; +use common::{tracing_stderr_init, INIT}; use futures::future::try_join; use futures::sink::SinkExt; use futures::stream::StreamExt; @@ -13,7 +13,7 @@ mod common; #[tokio::test] async fn positive_connect() { INIT.call_once(|| { - tracing_stdout_init(LevelFilter::TRACE); + tracing_stderr_init(LevelFilter::INFO); }); let handshaker_one_addr = "127.0.0.1:0".parse().unwrap(); diff --git a/packages/handshake/tests/test_filter_allow_all.rs b/packages/handshake/tests/test_filter_allow_all.rs index bd0bd4a79..d67032589 100644 --- a/packages/handshake/tests/test_filter_allow_all.rs +++ b/packages/handshake/tests/test_filter_allow_all.rs @@ -2,7 +2,7 @@ use std::any::Any; use std::net::SocketAddr; use std::time::Duration; -use common::{tracing_stdout_init, INIT}; +use common::{tracing_stderr_init, INIT}; use futures::sink::SinkExt; use futures::stream::{self, StreamExt}; use futures::FutureExt as _; @@ -43,7 +43,7 @@ impl HandshakeFilter for FilterAllowAll { #[tokio::test] async fn test_filter_all() { INIT.call_once(|| { - tracing_stdout_init(LevelFilter::TRACE); + tracing_stderr_init(LevelFilter::INFO); }); let handshaker_one_addr = "127.0.0.1:0".parse().unwrap(); @@ -102,7 +102,7 @@ async fn test_filter_all() { let res = tokio::time::timeout(Duration::from_millis(50), get_handshake).await; if let Ok(item) = res { - tracing::info!("handshake was produced: {item:?}"); + tracing::debug!("handshake was produced: {item:?}"); } else { panic!("expected item, but got a timeout!"); } diff --git a/packages/handshake/tests/test_filter_block_all.rs b/packages/handshake/tests/test_filter_block_all.rs index e70b976b2..fc1e2c342 100644 --- a/packages/handshake/tests/test_filter_block_all.rs +++ b/packages/handshake/tests/test_filter_block_all.rs @@ -2,7 +2,7 @@ use std::any::Any; use std::net::SocketAddr; use std::time::Duration; -use common::{tracing_stdout_init, INIT}; +use common::{tracing_stderr_init, INIT}; use futures::sink::SinkExt; use futures::stream::{self, StreamExt}; use futures::FutureExt; @@ -43,7 +43,7 @@ impl HandshakeFilter for FilterBlockAll { #[tokio::test] async fn test_filter_all() { INIT.call_once(|| { - tracing_stdout_init(LevelFilter::DEBUG); + tracing_stderr_init(LevelFilter::INFO); }); let handshaker_one_addr = "127.0.0.1:0".parse().unwrap(); @@ -104,7 +104,7 @@ async fn test_filter_all() { if let Ok(item) = res { panic!("expected timeout, but got a result: {item:?}"); } else { - tracing::info!("timeout was reached"); + tracing::debug!("timeout was reached"); } }); diff --git a/packages/handshake/tests/test_filter_whitelist_diff_data.rs b/packages/handshake/tests/test_filter_whitelist_diff_data.rs index d4bf8ae7e..2d071c1c0 100644 --- a/packages/handshake/tests/test_filter_whitelist_diff_data.rs +++ b/packages/handshake/tests/test_filter_whitelist_diff_data.rs @@ -1,7 +1,7 @@ use std::any::Any; use std::time::Duration; -use common::{tracing_stdout_init, INIT}; +use common::{tracing_stderr_init, INIT}; use futures::sink::SinkExt; use futures::stream::{self, StreamExt}; use futures::FutureExt as _; @@ -49,7 +49,7 @@ impl HandshakeFilter for FilterAllowHash { #[tokio::test] async fn test_filter_whitelist_diff_data() { INIT.call_once(|| { - tracing_stdout_init(LevelFilter::DEBUG); + tracing_stderr_init(LevelFilter::INFO); }); let handshaker_one_addr = "127.0.0.1:0".parse().unwrap(); @@ -115,7 +115,7 @@ async fn test_filter_whitelist_diff_data() { if let Ok(item) = res { panic!("expected timeout, but got a result: {item:?}"); } else { - tracing::info!("timeout was reached"); + tracing::debug!("timeout was reached"); } }); diff --git a/packages/handshake/tests/test_filter_whitelist_same_data.rs b/packages/handshake/tests/test_filter_whitelist_same_data.rs index 3f96e1ff4..236bc4328 100644 --- a/packages/handshake/tests/test_filter_whitelist_same_data.rs +++ b/packages/handshake/tests/test_filter_whitelist_same_data.rs @@ -1,7 +1,7 @@ use std::any::Any; use std::time::Duration; -use common::{tracing_stdout_init, INIT}; +use common::{tracing_stderr_init, INIT}; use futures::sink::SinkExt; use futures::stream::{self, StreamExt}; use futures::FutureExt as _; @@ -49,7 +49,7 @@ impl HandshakeFilter for FilterAllowHash { #[tokio::test] async fn test_filter_whitelist_same_data() { INIT.call_once(|| { - tracing_stdout_init(LevelFilter::TRACE); + tracing_stderr_init(LevelFilter::INFO); }); let handshaker_one_addr = "127.0.0.1:0".parse().unwrap(); @@ -113,7 +113,7 @@ async fn test_filter_whitelist_same_data() { let res = tokio::time::timeout(Duration::from_millis(50), get_handshake).await; if let Ok(item) = res { - tracing::info!("handshake was produced: {item:?}"); + tracing::debug!("handshake was produced: {item:?}"); } else { panic!("expected item, but got a timeout!"); } diff --git a/packages/metainfo/src/metainfo.rs b/packages/metainfo/src/metainfo.rs index bc756a7b9..f4da7fc7d 100644 --- a/packages/metainfo/src/metainfo.rs +++ b/packages/metainfo/src/metainfo.rs @@ -918,16 +918,14 @@ mod tests { } #[test] - #[should_panic( - expected = "called `Result::unwrap()` on an `Err` value: ParseError(BencodeParse(BencodeParseError(BytesEmpty { pos: 0 }, State { next_error: None, backtrace: InternalBacktrace { backtrace: None } })), State { next_error: None, backtrace: InternalBacktrace { backtrace: None } })" - )] + #[should_panic(expected = "called `Result::unwrap()` on an `Err` value: BencodeParse(BytesEmpty { pos: 0 })")] fn negative_parse_from_empty_bytes() { Metainfo::from_bytes(b"").unwrap(); } #[test] #[should_panic( - expected = "called `Result::unwrap()` on an `Err` value: ParseError(BencodeConvert(BencodeConvertError(MissingKey { key: [112, 105, 101, 99, 101, 32, 108, 101, 110, 103, 116, 104] }, State { next_error: None, backtrace: InternalBacktrace { backtrace: None } })), State { next_error: None, backtrace: InternalBacktrace { backtrace: None } })" + expected = "called `Result::unwrap()` on an `Err` value: BencodeConvert(MissingKey { key: [112, 105, 101, 99, 101, 32, 108, 101, 110, 103, 116, 104] })" )] fn negative_parse_with_no_piece_length() { let tracker = "udp://dummy_domain.com:8989"; @@ -954,7 +952,7 @@ mod tests { #[test] #[should_panic( - expected = "called `Result::unwrap()` on an `Err` value: ParseError(BencodeConvert(BencodeConvertError(MissingKey { key: [112, 105, 101, 99, 101, 115] }, State { next_error: None, backtrace: InternalBacktrace { backtrace: None } })), State { next_error: None, backtrace: InternalBacktrace { backtrace: None } })" + expected = "called `Result::unwrap()` on an `Err` value: BencodeConvert(MissingKey { key: [112, 105, 101, 99, 101, 115] })" )] fn negative_parse_with_no_pieces() { let tracker = "udp://dummy_domain.com:8989"; @@ -979,7 +977,7 @@ mod tests { #[test] #[should_panic( - expected = "called `Result::unwrap()` on an `Err` value: ParseError(BencodeConvert(BencodeConvertError(MissingKey { key: [102, 105, 108, 101, 115] }, State { next_error: None, backtrace: InternalBacktrace { backtrace: None } })), State { next_error: None, backtrace: InternalBacktrace { backtrace: None } })" + expected = "called `Result::unwrap()` on an `Err` value: BencodeConvert(MissingKey { key: [102, 105, 108, 101, 115] })" )] fn negative_parse_from_single_file_with_no_file_length() { let tracker = "udp://dummy_domain.com:8989"; @@ -1004,7 +1002,7 @@ mod tests { #[test] #[should_panic( - expected = "called `Result::unwrap()` on an `Err` value: ParseError(BencodeConvert(BencodeConvertError(MissingKey { key: [110, 97, 109, 101] }, State { next_error: None, backtrace: InternalBacktrace { backtrace: None } })), State { next_error: None, backtrace: InternalBacktrace { backtrace: None } })" + expected = "called `Result::unwrap()` on an `Err` value: BencodeConvert(MissingKey { key: [110, 97, 109, 101] })" )] fn negative_parse_from_single_file_with_no_file_name() { let tracker = "udp://dummy_domain.com:8989"; diff --git a/packages/peer/tests/common/mod.rs b/packages/peer/tests/common/mod.rs index 3425f95b9..be41c54f1 100644 --- a/packages/peer/tests/common/mod.rs +++ b/packages/peer/tests/common/mod.rs @@ -47,8 +47,11 @@ pub const DEFAULT_TIMEOUT: Duration = Duration::from_millis(500); pub static INIT: Once = Once::new(); #[allow(dead_code)] -pub fn tracing_stdout_init(filter: LevelFilter) { - let builder = tracing_subscriber::fmt().with_max_level(filter).with_ansi(true); +pub fn tracing_stderr_init(filter: LevelFilter) { + let builder = tracing_subscriber::fmt() + .with_max_level(filter) + .with_ansi(true) + .with_writer(std::io::stderr); builder.pretty().with_file(true).init(); diff --git a/packages/peer/tests/peer_manager_send_backpressure.rs b/packages/peer/tests/peer_manager_send_backpressure.rs index 40e466750..8bb0f5d66 100644 --- a/packages/peer/tests/peer_manager_send_backpressure.rs +++ b/packages/peer/tests/peer_manager_send_backpressure.rs @@ -1,5 +1,5 @@ use common::connected_channel::{connected_channel, ConnectedChannel}; -use common::{add_peer, remove_peer, tracing_stdout_init, INIT}; +use common::{add_peer, remove_peer, tracing_stderr_init, INIT}; use futures::SinkExt as _; use handshake::Extensions; use peer::error::PeerManagerError; @@ -19,7 +19,7 @@ type Peer = ConnectedChannel< #[tokio::test] async fn positive_peer_manager_send_backpressure() { INIT.call_once(|| { - tracing_stdout_init(LevelFilter::TRACE); + tracing_stderr_init(LevelFilter::INFO); }); let (mut send, mut recv) = PeerManagerBuilder::new() diff --git a/packages/select/Cargo.toml b/packages/select/Cargo.toml index 1ea72239c..cfab79534 100644 --- a/packages/select/Cargo.toml +++ b/packages/select/Cargo.toml @@ -31,3 +31,4 @@ tracing = "0" [dev-dependencies] tokio = { version = "1", features = ["full"] } +tracing-subscriber = "0" diff --git a/packages/select/src/revelation/honest.rs b/packages/select/src/revelation/honest.rs index 833b01e47..e359108f3 100644 --- a/packages/select/src/revelation/honest.rs +++ b/packages/select/src/revelation/honest.rs @@ -10,6 +10,7 @@ use handshake::InfoHash; use metainfo::Metainfo; use peer::messages::{BitFieldMessage, HaveMessage}; use peer::PeerInfo; +use tracing::instrument; use crate::revelation::error::RevealError; use crate::revelation::{IRevealMessage, ORevealMessage}; @@ -77,11 +78,17 @@ impl HonestRevealModule { } } + #[instrument(skip(self))] fn add_torrent(&mut self, metainfo: &Metainfo) -> Result<(), RevealError> { + tracing::trace!("adding torrent"); + let info_hash = metainfo.info().info_hash(); match self.torrents.entry(info_hash) { - Entry::Occupied(_) => Err(RevealError::InvalidMetainfoExists { hash: info_hash }), + Entry::Occupied(_) => { + tracing::error!("invalid metainfo"); + Err(RevealError::InvalidMetainfoExists { hash: info_hash }) + } Entry::Vacant(vac) => { let num_pieces = metainfo.info().pieces().count(); @@ -100,7 +107,10 @@ impl HonestRevealModule { } } + #[instrument(skip(self))] fn remove_torrent(&mut self, metainfo: &Metainfo) -> Result<(), RevealError> { + tracing::trace!("removing torrent"); + let info_hash = metainfo.info().info_hash(); if self.torrents.remove(&info_hash).is_none() { @@ -110,12 +120,15 @@ impl HonestRevealModule { } } + #[instrument(skip(self))] fn add_peer(&mut self, peer: PeerInfo) -> Result<(), RevealError> { + tracing::trace!("adding peer"); let info_hash = *peer.hash(); let out_bytes = &mut self.out_bytes; let out_queue = &mut self.out_queue; let Some(peers_info) = self.torrents.get_mut(&info_hash) else { + tracing::error!("adding peer error"); return Err(RevealError::InvalidMetainfoNotExists { hash: info_hash }); }; @@ -128,12 +141,19 @@ impl HonestRevealModule { let bitfield_bytes = out_bytes.split_off(0).freeze(); let bitfield = BitFieldMessage::new(bitfield_bytes); - out_queue.push_back(ORevealMessage::SendBitField(peer, bitfield)); + let message = ORevealMessage::SendBitField(peer, bitfield); + tracing::trace!("sending message: {message:?}"); + + out_queue.push_back(message); + if let Some(waker) = self.opt_stream_waker.take() { + waker.wake(); + } } Ok(()) } + #[instrument(skip(self))] fn remove_peer(&mut self, peer: PeerInfo) -> Result<(), RevealError> { let info_hash = *peer.hash(); @@ -146,7 +166,10 @@ impl HonestRevealModule { Ok(()) } + #[instrument(skip(self))] fn insert_piece(&mut self, hash: InfoHash, index: u64) -> Result<(), RevealError> { + tracing::trace!("inserting piece"); + let out_queue = &mut self.out_queue; let Some(peers_info) = self.torrents.get_mut(&hash) else { return Err(RevealError::InvalidMetainfoNotExists { hash }); @@ -161,7 +184,14 @@ impl HonestRevealModule { }) } else { for peer in &peers_info.peers { - out_queue.push_back(ORevealMessage::SendHave(*peer, HaveMessage::new(index.try_into().unwrap()))); + let message = ORevealMessage::SendHave(*peer, HaveMessage::new(index.try_into().unwrap())); + tracing::trace!("sending message: {message:?}"); + + out_queue.push_back(message); + + if let Some(waker) = self.opt_stream_waker.take() { + waker.wake(); + } } peers_info.status.insert(index); @@ -170,10 +200,17 @@ impl HonestRevealModule { } } + #[instrument(skip(self))] fn poll_next_message(&mut self, cx: &mut Context<'_>) -> Poll>> { + tracing::trace!("polling for next message"); + if let Some(message) = self.out_queue.pop_front() { + tracing::trace!("sending message {message:?}"); + Poll::Ready(Some(Ok(message))) } else { + tracing::trace!("no messages found... pending"); + self.opt_stream_waker = Some(cx.waker().clone()); Poll::Pending } @@ -191,11 +228,7 @@ impl Sink for HonestRevealModule { self.handle_message(item) } - fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { - if !self.out_queue.is_empty() { - cx.waker().wake_by_ref(); - return Poll::Pending; - } + fn poll_flush(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll> { Poll::Ready(Ok(())) } diff --git a/packages/select/src/revelation/mod.rs b/packages/select/src/revelation/mod.rs index 871987b49..a53e218c7 100644 --- a/packages/select/src/revelation/mod.rs +++ b/packages/select/src/revelation/mod.rs @@ -13,6 +13,7 @@ mod honest; pub use self::honest::{HonestRevealModule, HonestRevealModuleBuilder}; /// Enumeration of revelation messages that can be sent to a revelation module. +#[derive(Debug)] pub enum IRevealMessage { /// Control message. Control(ControlMessage), @@ -25,6 +26,7 @@ pub enum IRevealMessage { } /// Enumeration of revelation messages that can be received from a revelation module. +#[derive(Debug)] pub enum ORevealMessage { /// Send a `BitFieldMessage`. SendBitField(PeerInfo, BitFieldMessage), diff --git a/packages/select/tests/common/mod.rs b/packages/select/tests/common/mod.rs new file mode 100644 index 000000000..c952d9cc5 --- /dev/null +++ b/packages/select/tests/common/mod.rs @@ -0,0 +1,27 @@ +//----------------------------------------------------------------------------------// + +use std::sync::Once; + +use tracing::level_filters::LevelFilter; + +#[allow(dead_code)] +pub static INIT: Once = Once::new(); + +#[allow(dead_code)] +#[derive(PartialEq, Eq, Debug)] +pub enum TimeoutResult { + TimedOut, + GotResult, +} + +#[allow(dead_code)] +pub fn tracing_stderr_init(filter: LevelFilter) { + let builder = tracing_subscriber::fmt() + .with_max_level(filter) + .with_ansi(true) + .with_writer(std::io::stderr); + + builder.pretty().with_file(true).init(); + + tracing::info!("Logging initialized"); +} diff --git a/packages/select/tests/mod.rs b/packages/select/tests/select_tests.rs similarity index 82% rename from packages/select/tests/mod.rs rename to packages/select/tests/select_tests.rs index 761682dae..367f5c07e 100644 --- a/packages/select/tests/mod.rs +++ b/packages/select/tests/select_tests.rs @@ -1,3 +1,6 @@ +use std::time::Duration; + +use common::{tracing_stderr_init, INIT}; use futures::{SinkExt as _, StreamExt as _}; use handshake::Extensions; use metainfo::{DirectAccessor, Metainfo, MetainfoBuilder, PieceLength}; @@ -5,9 +8,12 @@ use peer::PeerInfo; use select::revelation::error::RevealError; use select::revelation::{HonestRevealModuleBuilder, IRevealMessage, ORevealMessage}; use select::ControlMessage; +use tracing::level_filters::LevelFilter; use util::bt; use util::bt::InfoHash; +mod common; + fn metainfo(num_pieces: usize) -> Metainfo { let data = vec![0u8; num_pieces]; @@ -31,6 +37,10 @@ fn peer_info(hash: InfoHash) -> PeerInfo { #[tokio::test] async fn positive_add_and_remove_metainfo() { + INIT.call_once(|| { + tracing_stderr_init(LevelFilter::INFO); + }); + let builder = HonestRevealModuleBuilder::new(); let mut module = builder.build(); let metainfo = metainfo(1); @@ -47,22 +57,32 @@ async fn positive_add_and_remove_metainfo() { #[tokio::test] async fn positive_send_bitfield_single_piece() { + INIT.call_once(|| { + tracing_stderr_init(LevelFilter::INFO); + }); + let builder = HonestRevealModuleBuilder::new(); let mut module = builder.build(); let metainfo = metainfo(8); let info_hash = metainfo.info().info_hash(); let peer_info = peer_info(info_hash); + tracing::debug!("sending add torrent..."); module .send(IRevealMessage::Control(ControlMessage::AddTorrent(metainfo))) .await .unwrap(); + + tracing::debug!("sending found good piece..."); module.send(IRevealMessage::FoundGoodPiece(info_hash, 0)).await.unwrap(); + + tracing::debug!("sending peer connected..."); module .send(IRevealMessage::Control(ControlMessage::PeerConnected(peer_info))) .await .unwrap(); + tracing::debug!("receiving send bit field..."); let message = module.next().await.unwrap(); if let Ok(ORevealMessage::SendBitField(info, bitfield)) = message { assert_eq!(peer_info, info); @@ -75,6 +95,10 @@ async fn positive_send_bitfield_single_piece() { #[tokio::test] async fn positive_send_bitfield_multiple_pieces() { + INIT.call_once(|| { + tracing_stderr_init(LevelFilter::INFO); + }); + let builder = HonestRevealModuleBuilder::new(); let mut module = builder.build(); let metainfo = metainfo(16); @@ -106,27 +130,44 @@ async fn positive_send_bitfield_multiple_pieces() { #[tokio::test] async fn negative_do_not_send_empty_bitfield() { + INIT.call_once(|| { + tracing_stderr_init(LevelFilter::INFO); + }); + let builder = HonestRevealModuleBuilder::new(); let mut module = builder.build(); let metainfo = metainfo(16); let info_hash = metainfo.info().info_hash(); let peer_info = peer_info(info_hash); + tracing::debug!("sending add torrent..."); module .send(IRevealMessage::Control(ControlMessage::AddTorrent(metainfo))) .await .unwrap(); + + tracing::debug!("sending peer connected..."); module .send(IRevealMessage::Control(ControlMessage::PeerConnected(peer_info))) .await .unwrap(); - let message = module.next().await; - assert!(message.is_none()); + tracing::debug!("attempt to receive a message..."); + let res = tokio::time::timeout(Duration::from_millis(50), module.next()).await; + + if let Ok(item) = res { + panic!("expected timeout, but got a result: {item:?}"); + } else { + tracing::debug!("timeout was reached"); + } } #[tokio::test] async fn negative_found_good_piece_out_of_range() { + INIT.call_once(|| { + tracing_stderr_init(LevelFilter::INFO); + }); + let builder = HonestRevealModuleBuilder::new(); let mut module = builder.build(); let metainfo = metainfo(8); @@ -151,6 +192,10 @@ async fn negative_found_good_piece_out_of_range() { #[tokio::test] async fn negative_all_pieces_good_found_good_piece_out_of_range() { + INIT.call_once(|| { + tracing_stderr_init(LevelFilter::INFO); + }); + let builder = HonestRevealModuleBuilder::new(); let mut module = builder.build(); let metainfo = metainfo(3); diff --git a/packages/utracker/Cargo.toml b/packages/utracker/Cargo.toml index e3bdd09c0..b80b7e2a4 100644 --- a/packages/utracker/Cargo.toml +++ b/packages/utracker/Cargo.toml @@ -25,6 +25,8 @@ futures = "0" nom = "7" rand = "0" umio = "0" +tracing = "0" [dev-dependencies] tokio = { version = "1", features = ["full"] } +tracing-subscriber = "0" diff --git a/packages/utracker/src/option.rs b/packages/utracker/src/option.rs index fdd139ce0..63945a62e 100644 --- a/packages/utracker/src/option.rs +++ b/packages/utracker/src/option.rs @@ -228,6 +228,7 @@ mod tests { use super::{AnnounceOptions, URLDataOption}; #[test] + #[ignore = "unable to write into a too-small buffer..."] fn positive_write_eof_option() { let mut received = []; diff --git a/packages/utracker/src/scrape.rs b/packages/utracker/src/scrape.rs index aae164e44..532b0b4d0 100644 --- a/packages/utracker/src/scrape.rs +++ b/packages/utracker/src/scrape.rs @@ -441,9 +441,9 @@ mod tests { #[test] fn positive_parse_request_empty() { - let hash_one = []; + let hash_none = []; - let received = ScrapeRequest::from_bytes(&hash_one); + let received = ScrapeRequest::from_bytes(&hash_none); let expected = ScrapeRequest::new(); diff --git a/packages/utracker/tests/common/mod.rs b/packages/utracker/tests/common/mod.rs index 0ddd8ede3..c150f5d09 100644 --- a/packages/utracker/tests/common/mod.rs +++ b/packages/utracker/tests/common/mod.rs @@ -1,12 +1,13 @@ use std::collections::{HashMap, HashSet}; use std::net::{SocketAddr, SocketAddrV4, SocketAddrV6}; -use std::sync::{Arc, Mutex}; +use std::sync::{Arc, Mutex, Once}; use futures::channel::mpsc::{self, UnboundedReceiver, UnboundedSender}; use futures::sink::SinkExt; use futures::stream::StreamExt; use futures::{Sink, Stream}; use handshake::DiscoveryInfo; +use tracing::level_filters::LevelFilter; use util::bt::{InfoHash, PeerId}; use util::trans::{LocallyShuffledIds, TransactionIds}; use utracker::announce::{AnnounceEvent, AnnounceRequest, AnnounceResponse}; @@ -16,6 +17,28 @@ use utracker::{HandshakerMessage, ServerHandler, ServerResult}; const NUM_PEERS_RETURNED: usize = 20; +#[allow(dead_code)] +pub static INIT: Once = Once::new(); + +#[allow(dead_code)] +#[derive(PartialEq, Eq, Debug)] +pub enum TimeoutResult { + TimedOut, + GotResult, +} + +#[allow(dead_code)] +pub fn tracing_stderr_init(filter: LevelFilter) { + let builder = tracing_subscriber::fmt() + .with_max_level(filter) + .with_ansi(true) + .with_writer(std::io::stderr); + + builder.pretty().with_file(true).init(); + + tracing::info!("Logging initialized"); +} + #[derive(Clone)] pub struct MockTrackerHandler { inner: Arc>, diff --git a/packages/utracker/tests/test_announce_start.rs b/packages/utracker/tests/test_announce_start.rs index dd83ca25f..7d2ef258d 100644 --- a/packages/utracker/tests/test_announce_start.rs +++ b/packages/utracker/tests/test_announce_start.rs @@ -2,9 +2,10 @@ use std::net::SocketAddr; use std::thread::{self}; use std::time::Duration; -use common::{handshaker, MockTrackerHandler}; +use common::{handshaker, tracing_stderr_init, MockTrackerHandler, INIT}; use futures::StreamExt as _; use handshake::Protocol; +use tracing::level_filters::LevelFilter; use util::bt::{self}; use utracker::announce::{AnnounceEvent, ClientState}; use utracker::{ClientRequest, HandshakerMessage, TrackerClient, TrackerServer}; @@ -13,6 +14,10 @@ mod common; #[tokio::test] async fn positive_announce_started() { + INIT.call_once(|| { + tracing_stderr_init(LevelFilter::INFO); + }); + let (sink, mut stream) = handshaker(); let server_addr = "127.0.0.1:3501".parse().unwrap(); diff --git a/packages/utracker/tests/test_announce_stop.rs b/packages/utracker/tests/test_announce_stop.rs index 392f81cbf..713ad00e9 100644 --- a/packages/utracker/tests/test_announce_stop.rs +++ b/packages/utracker/tests/test_announce_stop.rs @@ -1,8 +1,9 @@ use std::thread::{self}; use std::time::Duration; -use common::{handshaker, MockTrackerHandler}; +use common::{handshaker, tracing_stderr_init, MockTrackerHandler, INIT}; use futures::StreamExt as _; +use tracing::level_filters::LevelFilter; use util::bt::{self}; use utracker::announce::{AnnounceEvent, ClientState}; use utracker::{ClientRequest, HandshakerMessage, TrackerClient, TrackerServer}; @@ -11,6 +12,10 @@ mod common; #[tokio::test] async fn positive_announce_stopped() { + INIT.call_once(|| { + tracing_stderr_init(LevelFilter::INFO); + }); + let (sink, mut stream) = handshaker(); let server_addr = "127.0.0.1:3502".parse().unwrap(); diff --git a/packages/utracker/tests/test_client_drop.rs b/packages/utracker/tests/test_client_drop.rs index 3d53fc41a..1fc4cba1d 100644 --- a/packages/utracker/tests/test_client_drop.rs +++ b/packages/utracker/tests/test_client_drop.rs @@ -1,7 +1,8 @@ use std::net::SocketAddr; -use common::handshaker; +use common::{handshaker, tracing_stderr_init, INIT}; use futures::StreamExt as _; +use tracing::level_filters::LevelFilter; use util::bt::{self}; use utracker::announce::{AnnounceEvent, ClientState}; use utracker::{ClientError, ClientRequest, HandshakerMessage, TrackerClient}; @@ -10,6 +11,10 @@ mod common; #[tokio::test] async fn positive_client_request_failed() { + INIT.call_once(|| { + tracing_stderr_init(LevelFilter::INFO); + }); + let (sink, mut stream) = handshaker(); let server_addr: SocketAddr = "127.0.0.1:3503".parse().unwrap(); diff --git a/packages/utracker/tests/test_client_full.rs b/packages/utracker/tests/test_client_full.rs index 7ebaf0fdf..8d29aae8e 100644 --- a/packages/utracker/tests/test_client_full.rs +++ b/packages/utracker/tests/test_client_full.rs @@ -1,7 +1,8 @@ use std::mem; -use common::handshaker; +use common::{handshaker, tracing_stderr_init, INIT}; use futures::StreamExt as _; +use tracing::level_filters::LevelFilter; use util::bt::{self}; use utracker::announce::{AnnounceEvent, ClientState}; use utracker::{ClientRequest, TrackerClient}; @@ -10,6 +11,10 @@ mod common; #[tokio::test] async fn positive_client_request_dropped() { + INIT.call_once(|| { + tracing_stderr_init(LevelFilter::INFO); + }); + let (sink, stream) = handshaker(); let server_addr = "127.0.0.1:3504".parse().unwrap(); diff --git a/packages/utracker/tests/test_connect.rs b/packages/utracker/tests/test_connect.rs index 0a5c20970..450ad29b3 100644 --- a/packages/utracker/tests/test_connect.rs +++ b/packages/utracker/tests/test_connect.rs @@ -1,8 +1,9 @@ use std::thread::{self}; use std::time::Duration; -use common::{handshaker, MockTrackerHandler}; +use common::{handshaker, tracing_stderr_init, MockTrackerHandler, INIT}; use futures::StreamExt as _; +use tracing::level_filters::LevelFilter; use util::bt::{self}; use utracker::announce::{AnnounceEvent, ClientState}; use utracker::{ClientRequest, HandshakerMessage, TrackerClient, TrackerServer}; @@ -11,6 +12,10 @@ mod common; #[tokio::test] async fn positive_receive_connect_id() { + INIT.call_once(|| { + tracing_stderr_init(LevelFilter::INFO); + }); + let (sink, mut stream) = handshaker(); let server_addr = "127.0.0.1:3505".parse().unwrap(); diff --git a/packages/utracker/tests/test_connect_cache.rs b/packages/utracker/tests/test_connect_cache.rs index 56e2b9449..fe63581d3 100644 --- a/packages/utracker/tests/test_connect_cache.rs +++ b/packages/utracker/tests/test_connect_cache.rs @@ -1,8 +1,9 @@ use std::thread::{self}; use std::time::Duration; -use common::MockTrackerHandler; +use common::{tracing_stderr_init, MockTrackerHandler, INIT}; use futures::StreamExt as _; +use tracing::level_filters::LevelFilter; use util::bt::{self}; use utracker::{ClientRequest, TrackerClient, TrackerServer}; @@ -10,6 +11,10 @@ mod common; #[tokio::test] async fn positive_connection_id_cache() { + INIT.call_once(|| { + tracing_stderr_init(LevelFilter::INFO); + }); + let (sink, mut stream) = common::handshaker(); let server_addr = "127.0.0.1:3506".parse().unwrap(); diff --git a/packages/utracker/tests/test_scrape.rs b/packages/utracker/tests/test_scrape.rs index 412602295..68d5be768 100644 --- a/packages/utracker/tests/test_scrape.rs +++ b/packages/utracker/tests/test_scrape.rs @@ -1,8 +1,9 @@ use std::thread::{self}; use std::time::Duration; -use common::{handshaker, MockTrackerHandler}; +use common::{handshaker, tracing_stderr_init, MockTrackerHandler, INIT}; use futures::StreamExt as _; +use tracing::level_filters::LevelFilter; use util::bt::{self}; use utracker::{ClientRequest, HandshakerMessage, TrackerClient, TrackerServer}; @@ -10,6 +11,10 @@ mod common; #[tokio::test] async fn positive_scrape() { + INIT.call_once(|| { + tracing_stderr_init(LevelFilter::INFO); + }); + let (sink, mut stream) = handshaker(); let server_addr = "127.0.0.1:3507".parse().unwrap(); diff --git a/packages/utracker/tests/test_server_drop.rs b/packages/utracker/tests/test_server_drop.rs index 1e4ee51a5..21d2090b6 100644 --- a/packages/utracker/tests/test_server_drop.rs +++ b/packages/utracker/tests/test_server_drop.rs @@ -1,7 +1,8 @@ use std::net::UdpSocket; use std::time::Duration; -use common::MockTrackerHandler; +use common::{tracing_stderr_init, MockTrackerHandler, INIT}; +use tracing::level_filters::LevelFilter; use utracker::request::{self, RequestType, TrackerRequest}; use utracker::TrackerServer; @@ -10,6 +11,10 @@ mod common; #[test] #[allow(unused)] fn positive_server_dropped() { + INIT.call_once(|| { + tracing_stderr_init(LevelFilter::INFO); + }); + let server_addr = "127.0.0.1:3508".parse().unwrap(); let mock_handler = MockTrackerHandler::new();