mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-23 18:32:17 +00:00
Use the same test::run_test
function for async gpui::test
s
This commit is contained in:
parent
9c7ef39da6
commit
f09798c4a7
2 changed files with 16 additions and 64 deletions
|
@ -17,11 +17,12 @@ fn init_logger() {
|
||||||
.init();
|
.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run_sync_test(
|
pub fn run_test(
|
||||||
mut num_iterations: u64,
|
mut num_iterations: u64,
|
||||||
mut starting_seed: u64,
|
mut starting_seed: u64,
|
||||||
max_retries: usize,
|
max_retries: usize,
|
||||||
test_fn: &mut (dyn RefUnwindSafe + Fn(&mut MutableAppContext, u64)),
|
test_fn: &mut (dyn RefUnwindSafe
|
||||||
|
+ Fn(&mut MutableAppContext, Rc<platform::test::ForegroundPlatform>, u64)),
|
||||||
) {
|
) {
|
||||||
let is_randomized = num_iterations > 1;
|
let is_randomized = num_iterations > 1;
|
||||||
if is_randomized {
|
if is_randomized {
|
||||||
|
@ -62,7 +63,7 @@ pub fn run_sync_test(
|
||||||
font_cache.clone(),
|
font_cache.clone(),
|
||||||
0,
|
0,
|
||||||
);
|
);
|
||||||
cx.update(|cx| test_fn(cx, seed));
|
cx.update(|cx| test_fn(cx, foreground_platform.clone(), seed));
|
||||||
|
|
||||||
atomic_seed.fetch_add(1, SeqCst);
|
atomic_seed.fetch_add(1, SeqCst);
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,10 +76,10 @@ pub fn test(args: TokenStream, function: TokenStream) -> TokenStream {
|
||||||
inner_fn_args.extend(quote!(
|
inner_fn_args.extend(quote!(
|
||||||
#namespace::TestAppContext::new(
|
#namespace::TestAppContext::new(
|
||||||
foreground_platform.clone(),
|
foreground_platform.clone(),
|
||||||
platform.clone(),
|
cx.platform().clone(),
|
||||||
foreground.clone(),
|
cx.foreground().clone(),
|
||||||
background.clone(),
|
cx.background().clone(),
|
||||||
font_cache.clone(),
|
cx.font_cache().clone(),
|
||||||
#first_entity_id,
|
#first_entity_id,
|
||||||
),
|
),
|
||||||
));
|
));
|
||||||
|
@ -111,61 +111,12 @@ pub fn test(args: TokenStream, function: TokenStream) -> TokenStream {
|
||||||
fn #outer_fn_name() {
|
fn #outer_fn_name() {
|
||||||
#inner_fn
|
#inner_fn
|
||||||
|
|
||||||
let is_randomized = #num_iterations > 1;
|
#namespace::test::run_test(
|
||||||
let mut num_iterations = #num_iterations as u64;
|
#num_iterations as u64,
|
||||||
let mut starting_seed = #starting_seed as u64;
|
#starting_seed as u64,
|
||||||
if is_randomized {
|
#max_retries,
|
||||||
if let Ok(value) = std::env::var("SEED") {
|
&mut |cx, foreground_platform, seed| cx.foreground().run(#inner_fn_name(#inner_fn_args))
|
||||||
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);
|
|
||||||
foreground.run(#inner_fn_name(#inner_fn_args));
|
|
||||||
atomic_seed.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
match result {
|
|
||||||
Ok(result) => {
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -192,11 +143,11 @@ pub fn test(args: TokenStream, function: TokenStream) -> TokenStream {
|
||||||
fn #outer_fn_name() {
|
fn #outer_fn_name() {
|
||||||
#inner_fn
|
#inner_fn
|
||||||
|
|
||||||
#namespace::test::run_sync_test(
|
#namespace::test::run_test(
|
||||||
#num_iterations as u64,
|
#num_iterations as u64,
|
||||||
#starting_seed as u64,
|
#starting_seed as u64,
|
||||||
#max_retries,
|
#max_retries,
|
||||||
&mut |cx, seed| #inner_fn_name(#inner_fn_args)
|
&mut |cx, _, seed| #inner_fn_name(#inner_fn_args)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue