diff --git a/Cargo.lock b/Cargo.lock index 00b5d6d..fcb6a88 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -117,16 +117,6 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "ctor" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd4056f63fce3b82d852c3da92b08ea59959890813a7f4ce9c0ff85b10cf301b" -dependencies = [ - "quote", - "syn 2.0.12", -] - [[package]] name = "env_logger" version = "0.8.4" @@ -274,7 +264,6 @@ version = "1.0.0" dependencies = [ "base64 0.21.0", "const-str", - "ctor", "heapless", "impls", "libc", @@ -436,7 +425,7 @@ checksum = "b22a693222d716a9587786f37ac3f6b4faedb5b80c23914e7303ff5a1d8016e9" dependencies = [ "proc-macro2", "quote", - "syn 1.0.109", + "syn", ] [[package]] @@ -636,17 +625,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "syn" -version = "2.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79d9531f94112cfc3e4c8f5f02cb2b58f72c97b7efd85f70203cc6d8efda5927" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - [[package]] name = "tempfile" version = "3.4.0" @@ -724,7 +702,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 1.0.109", + "syn", "wasm-bindgen-shared", ] @@ -746,7 +724,7 @@ checksum = "2aff81306fcac3c7515ad4e177f521b5c9a15f2b08f4e32d823066102f35a5f6" dependencies = [ "proc-macro2", "quote", - "syn 1.0.109", + "syn", "wasm-bindgen-backend", "wasm-bindgen-shared", ] diff --git a/Cargo.toml b/Cargo.toml index ae73a3d..6ae3a40 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,8 +20,6 @@ base64 = "0.21.0" once_cell = "1.17.1" [dev-dependencies] -# Simplifies test setup and the `waitid` hack. -ctor = "0.2.0" quickcheck = "1.0.3" quickcheck_macros = "1.0.0" tempfile = "3.4.0" diff --git a/src/parent/ipc/test_utils.rs b/src/parent/ipc/test_utils.rs index c477c64..45367d0 100644 --- a/src/parent/ipc/test_utils.rs +++ b/src/parent/ipc/test_utils.rs @@ -74,6 +74,7 @@ impl StaticState { } pub fn init_test_state_with_key_dir(&'static self, key_dir: std::path::PathBuf) { + init_logger(); self.state.init_dynamic(ParentIpcDynamic { port: std::num::NonZeroU16::new(1).unwrap(), child_user_group: UserGroup { diff --git a/src/state/byte_count_map.rs b/src/state/byte_count_map.rs index 74a8e47..3e41c42 100644 --- a/src/state/byte_count_map.rs +++ b/src/state/byte_count_map.rs @@ -296,6 +296,7 @@ mod tests { #[test] fn works_on_one_thread() { + init_logger(); static S: PromState = PromState::new(); S.add_message_line_ingested(&map_key(b"one"), 123); @@ -372,6 +373,7 @@ mod tests { #[test] fn works_on_two_contending_threads() { + init_logger(); // Pre-allocate everything so it won't take a long time to run with all the allocations. // This is one of the slowest tests in Miri, so it's particularly helpful here. static S: PromState = PromState::new(); @@ -468,6 +470,7 @@ mod tests { // Extremely slow in Miri (might very well take over an hour). Just skip it. #[cfg_attr(miri, ignore)] fn works_on_a_hundred_contending_threads() { + init_logger(); // Pre-allocate everything so it won't take a long time to run with all the allocations. static S: PromState = PromState::new(); diff --git a/src/test_utils/spy/logger_spy.rs b/src/test_utils/spy/logger_spy.rs index f9a0f10..294fc2f 100644 --- a/src/test_utils/spy/logger_spy.rs +++ b/src/test_utils/spy/logger_spy.rs @@ -162,21 +162,23 @@ impl std::ops::Deref for LoggerCaptureGuard { } } -// Initialize this for all tests. Easier than trying to pump it through literally everything, and -// I can also use this to track down any/all stray logs. -#[ctor::ctor] -fn init_logger() { - // Don't log `trace!(...)` stuff. - if std::env::var("RUST_TRACE") == Ok("1".into()) { - log::set_max_level(log::LevelFilter::Trace); - } else { - log::set_max_level(log::LevelFilter::Debug); - } - log::set_logger(&TEST_LOGGER).unwrap(); +pub fn init_logger() { + static ONCE: std::sync::Once = std::sync::Once::new(); + ONCE.call_once(|| { + // Don't log `trace!(...)` stuff. + let level = if std::env::var("RUST_TRACE") == Ok("1".into()) { + log::LevelFilter::Trace + } else { + log::LevelFilter::Debug + }; + log::set_max_level(level); + log::set_logger(&TEST_LOGGER).unwrap(); + }); } #[must_use = "The returned guard must be live for the whole test to ensure all logs are captured."] pub fn setup_capture_logger() -> LoggerCaptureGuard { + init_logger(); LoggerCaptureGuard(LoggerGuard::new(LoggerKind::LoggerVec(LogCapture { inner: Mutex::new(Vec::new()), })))