From 60adf36db26af13e87e19b651a43b129588fd18d Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Fri, 6 Mar 2020 18:28:13 -0500 Subject: [PATCH] Fix some tests --- compiler/solve/tests/helpers/mod.rs | 25 +++++++++++++++++++++++++ compiler/uniq/tests/helpers/mod.rs | 25 +++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/compiler/solve/tests/helpers/mod.rs b/compiler/solve/tests/helpers/mod.rs index 402fb9f844..e02d8fec6c 100644 --- a/compiler/solve/tests/helpers/mod.rs +++ b/compiler/solve/tests/helpers/mod.rs @@ -46,6 +46,31 @@ pub fn infer_expr( (content, solved.into_inner()) } +/// Used in the with_larger_debug_stack() function, for tests that otherwise +/// run out of stack space in debug builds (but don't in --release builds) +#[allow(dead_code)] +const EXPANDED_STACK_SIZE: usize = 4 * 1024 * 1024; + +/// Without this, some tests pass in `cargo test --release` but fail without +/// the --release flag because they run out of stack space. This increases +/// stack size for debug builds only, while leaving the stack space at the default +/// amount for release builds. +#[allow(dead_code)] +#[cfg(debug_assertions)] +pub fn with_larger_debug_stack(run_test: F) +where + F: FnOnce() -> (), + F: Send, + F: 'static, +{ + std::thread::Builder::new() + .stack_size(EXPANDED_STACK_SIZE) + .spawn(run_test) + .expect("Error while spawning expanded dev stack size thread") + .join() + .expect("Error while joining expanded dev stack size thread") +} + /// In --release builds, don't increase the stack size. Run the test normally. /// This way, we find out if any of our tests are blowing the stack even after /// optimizations in release builds. diff --git a/compiler/uniq/tests/helpers/mod.rs b/compiler/uniq/tests/helpers/mod.rs index 402fb9f844..e02d8fec6c 100644 --- a/compiler/uniq/tests/helpers/mod.rs +++ b/compiler/uniq/tests/helpers/mod.rs @@ -46,6 +46,31 @@ pub fn infer_expr( (content, solved.into_inner()) } +/// Used in the with_larger_debug_stack() function, for tests that otherwise +/// run out of stack space in debug builds (but don't in --release builds) +#[allow(dead_code)] +const EXPANDED_STACK_SIZE: usize = 4 * 1024 * 1024; + +/// Without this, some tests pass in `cargo test --release` but fail without +/// the --release flag because they run out of stack space. This increases +/// stack size for debug builds only, while leaving the stack space at the default +/// amount for release builds. +#[allow(dead_code)] +#[cfg(debug_assertions)] +pub fn with_larger_debug_stack(run_test: F) +where + F: FnOnce() -> (), + F: Send, + F: 'static, +{ + std::thread::Builder::new() + .stack_size(EXPANDED_STACK_SIZE) + .spawn(run_test) + .expect("Error while spawning expanded dev stack size thread") + .join() + .expect("Error while joining expanded dev stack size thread") +} + /// In --release builds, don't increase the stack size. Run the test normally. /// This way, we find out if any of our tests are blowing the stack even after /// optimizations in release builds.