Skip to content

Commit

Permalink
Fix #21 by dropping ctor
Browse files Browse the repository at this point in the history
  • Loading branch information
dead-claudia committed Jul 3, 2024
1 parent 8f16bab commit 5b2a6be
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 38 deletions.
28 changes: 3 additions & 25 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions src/parent/ipc/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions src/state/byte_count_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();

Expand Down
24 changes: 13 additions & 11 deletions src/test_utils/spy/logger_spy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
})))
Expand Down

0 comments on commit 5b2a6be

Please sign in to comment.