Unverified Commit f145b8fa authored by vercel-fleet-prod[bot]'s avatar vercel-fleet-prod[bot] Committed by GitHub

test(turbo-tasks): avoid wasm runtime shutdown wait

Co-authored-by: 's avatarTobias Koppers <1365881+sokra@users.noreply.github.com>
Co-authored-by: 's avatarLuke Sandberg <210140+lukesandberg@users.noreply.github.com>
parent 332b0c51
...@@ -359,14 +359,18 @@ mod tests { ...@@ -359,14 +359,18 @@ mod tests {
/// Helpers must actually add parallelism when threads are available: jobs that each block /// Helpers must actually add parallelism when threads are available: jobs that each block
/// briefly should complete in far less than their serial sum. /// briefly should complete in far less than their serial sum.
#[tokio::test(flavor = "multi_thread", worker_threads = 4)] #[test]
// Node Worker startup makes the native timing bound too strict on wasm. A later layer uses a fn test_scope_runs_in_parallel() {
// platform-aware bound that still distinguishes parallel from serial execution. let runtime = tokio::runtime::Builder::new_multi_thread()
#[cfg_attr( .worker_threads(4)
target_family = "wasm", .enable_all()
ignore = "timing bound is too strict for Node Worker startup" .build()
)] .unwrap();
async fn test_scope_runs_in_parallel() { runtime.block_on(test_scope_runs_in_parallel_impl());
runtime.shutdown_background();
}
async fn test_scope_runs_in_parallel_impl() {
const JOBS: usize = 16; const JOBS: usize = 16;
const PER_JOB: Duration = Duration::from_millis(50); const PER_JOB: Duration = Duration::from_millis(50);
let started = Instant::now(); let started = Instant::now();
...@@ -385,10 +389,14 @@ mod tests { ...@@ -385,10 +389,14 @@ mod tests {
.unwrap(); .unwrap();
let elapsed = started.elapsed(); let elapsed = started.elapsed();
assert_eq!(results.len(), JOBS); assert_eq!(results.len(), JOBS);
// Half the serial time is a loose bound on purpose: 4 threads should beat it comfortably, let serial_time = JOBS as u32 * PER_JOB;
// so a slow machine won't make this flaky. #[cfg(not(target_family = "wasm"))]
let deadline = serial_time / 2;
// Node Worker startup is expensive, but the test must still finish faster than serial work.
#[cfg(target_family = "wasm")]
let deadline = serial_time - PER_JOB;
assert!( assert!(
elapsed < (JOBS as u32 * PER_JOB) / 2, elapsed < deadline,
"scope_bounded took {elapsed:?}; expected parallel speedup across worker threads" "scope_bounded took {elapsed:?}; expected parallel speedup across worker threads"
); );
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment