Minimize code generation for synchronous gpui::test
macro
Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
parent
7a05461c50
commit
9c7ef39da6
5 changed files with 94 additions and 71 deletions
|
@ -192,70 +192,12 @@ pub fn test(args: TokenStream, function: TokenStream) -> TokenStream {
|
|||
fn #outer_fn_name() {
|
||||
#inner_fn
|
||||
|
||||
let is_randomized = #num_iterations > 1;
|
||||
let mut num_iterations = #num_iterations as u64;
|
||||
let mut starting_seed = #starting_seed as u64;
|
||||
if is_randomized {
|
||||
if let Ok(value) = std::env::var("SEED") {
|
||||
starting_seed = value.parse().expect("invalid SEED variable");
|
||||
}
|
||||
if let Ok(value) = std::env::var("ITERATIONS") {
|
||||
num_iterations = value.parse().expect("invalid ITERATIONS variable");
|
||||
}
|
||||
}
|
||||
|
||||
let mut atomic_seed = std::sync::atomic::AtomicU64::new(starting_seed as u64);
|
||||
let mut retries = 0;
|
||||
|
||||
loop {
|
||||
let result = std::panic::catch_unwind(|| {
|
||||
let foreground_platform = std::rc::Rc::new(#namespace::platform::test::foreground_platform());
|
||||
let platform = std::sync::Arc::new(#namespace::platform::test::platform());
|
||||
let font_system = #namespace::Platform::fonts(platform.as_ref());
|
||||
let font_cache = std::sync::Arc::new(#namespace::FontCache::new(font_system));
|
||||
|
||||
loop {
|
||||
let seed = atomic_seed.load(std::sync::atomic::Ordering::SeqCst);
|
||||
if seed >= starting_seed + num_iterations {
|
||||
break;
|
||||
}
|
||||
|
||||
if is_randomized {
|
||||
dbg!(seed);
|
||||
}
|
||||
|
||||
let (foreground, background) = #namespace::executor::deterministic(seed);
|
||||
let mut cx = #namespace::TestAppContext::new(
|
||||
foreground_platform.clone(),
|
||||
platform.clone(),
|
||||
foreground.clone(),
|
||||
background.clone(),
|
||||
font_cache.clone(),
|
||||
0,
|
||||
);
|
||||
cx.update(|cx| #inner_fn_name(#inner_fn_args));
|
||||
|
||||
atomic_seed.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
|
||||
}
|
||||
});
|
||||
|
||||
match result {
|
||||
Ok(_) => {
|
||||
break;
|
||||
}
|
||||
Err(error) => {
|
||||
if retries < #max_retries {
|
||||
retries += 1;
|
||||
println!("retrying: attempt {}", retries);
|
||||
} else {
|
||||
if is_randomized {
|
||||
eprintln!("failing seed: {}", atomic_seed.load(std::sync::atomic::Ordering::SeqCst));
|
||||
}
|
||||
std::panic::resume_unwind(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#namespace::test::run_sync_test(
|
||||
#num_iterations as u64,
|
||||
#starting_seed as u64,
|
||||
#max_retries,
|
||||
&mut |cx, seed| #inner_fn_name(#inner_fn_args)
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue