diff --git a/turbopack/crates/turbo-tasks-fetch/tests/fetch.rs b/turbopack/crates/turbo-tasks-fetch/tests/fetch.rs index 12e97eede4ee2..5f4057dd571f8 100644 --- a/turbopack/crates/turbo-tasks-fetch/tests/fetch.rs +++ b/turbopack/crates/turbo-tasks-fetch/tests/fetch.rs @@ -10,7 +10,7 @@ static REGISTRATION: Registration = register!(turbo_tasks_fetch::register); #[tokio::test] async fn basic_get() { - run(®ISTRATION, async { + run(®ISTRATION, || async { let server = httpmock::MockServer::start(); let resource_mock = server.mock(|when, then| { when.path("/foo.woff"); @@ -29,18 +29,20 @@ async fn basic_get() { match result { Err(_) => panic!(), Ok(response) => { - let response = response.await.unwrap(); + let response = response.await?; assert_eq!(response.status, 200); - assert_eq!(*response.body.to_string().await.unwrap(), "responsebody"); + assert_eq!(*response.body.to_string().await?, "responsebody"); } } + anyhow::Ok(()) }) .await + .unwrap() } #[tokio::test] async fn sends_user_agent() { - run(®ISTRATION, async { + run(®ISTRATION, || async { let server = httpmock::MockServer::start(); let resource_mock = server.mock(|when, then| { when.path("/foo.woff").header("User-Agent", "foo"); @@ -58,18 +60,20 @@ async fn sends_user_agent() { let Ok(response) = result else { panic!() }; - let response = response.await.unwrap(); + let response = response.await?; assert_eq!(response.status, 200); - assert_eq!(*response.body.to_string().await.unwrap(), "responsebody"); + assert_eq!(*response.body.to_string().await?, "responsebody"); + anyhow::Ok(()) }) .await + .unwrap() } // This is temporary behavior. // TODO: Implement invalidation that respects Cache-Control headers. #[tokio::test] async fn invalidation_does_not_invalidate() { - run(®ISTRATION, async { + run(®ISTRATION, || async { let server = httpmock::MockServer::start(); let resource_mock = server.mock(|when, then| { when.path("/foo.woff").header("User-Agent", "foo"); @@ -79,50 +83,53 @@ async fn invalidation_does_not_invalidate() { let url = Vc::cell(server.url("/foo.woff").into()); let user_agent = Vc::cell(Some("foo".into())); let proxy = Vc::cell(None); - let result = &*fetch(url, user_agent, proxy).await.unwrap(); + let result = &*fetch(url, user_agent, proxy).await?; resource_mock.assert(); let Ok(response_vc) = result else { panic!() }; - let response = response_vc.await.unwrap(); + let response = response_vc.await?; assert_eq!(response.status, 200); - assert_eq!(*response.body.to_string().await.unwrap(), "responsebody"); + assert_eq!(*response.body.to_string().await?, "responsebody"); - let second_result = &*fetch(url, user_agent, proxy).await.unwrap(); + let second_result = &*fetch(url, user_agent, proxy).await?; let Ok(second_response_vc) = second_result else { panic!() }; - let second_response = second_response_vc.await.unwrap(); + let second_response = second_response_vc.await?; // Assert that a second request is never sent -- the result is cached via turbo // tasks resource_mock.assert_hits(1); assert_eq!(response, second_response); + anyhow::Ok(()) }) .await + .unwrap() } #[tokio::test] async fn errors_on_failed_connection() { - run(®ISTRATION, async { + run(®ISTRATION, || async { let url = "https://doesnotexist/foo.woff"; - let result = &*fetch(Vc::cell(url.into()), Vc::cell(None), Vc::cell(None)).await.unwrap(); + let result = &*fetch(Vc::cell(url.into()), Vc::cell(None), Vc::cell(None)).await?; let Err(err_vc) = result else { panic!() }; - let err = &*err_vc.await.unwrap(); - assert_eq!(*err.kind.await.unwrap(), FetchErrorKind::Connect); - assert_eq!(*err.url.await.unwrap(), url); + let err = &*err_vc.await?; + assert_eq!(*err.kind.await?, FetchErrorKind::Connect); + assert_eq!(*err.url.await?, url); let issue = err_vc.to_issue(IssueSeverity::Error.into(), get_issue_context()); - assert_eq!(*issue.severity().await.unwrap(), IssueSeverity::Error); - assert_eq!(*issue.description().await.unwrap().unwrap().await.unwrap(), StyledString::Text("There was an issue establishing a connection while requesting https://doesnotexist/foo.woff.".into())); + assert_eq!(*issue.severity().await?, IssueSeverity::Error); + assert_eq!(*issue.description().await?.unwrap().await?, StyledString::Text("There was an issue establishing a connection while requesting https://doesnotexist/foo.woff.".into())); + anyhow::Ok(()) }) - .await + .await.unwrap() } #[tokio::test] async fn errors_on_404() { - run(®ISTRATION, async { + run(®ISTRATION, || async { let server = httpmock::MockServer::start(); let resource_url = server.url("/"); let result = &*fetch( @@ -133,17 +140,14 @@ async fn errors_on_404() { .await .unwrap(); let Err(err_vc) = result else { panic!() }; - let err = &*err_vc.await.unwrap(); - assert!(matches!( - *err.kind.await.unwrap(), - FetchErrorKind::Status(404) - )); - assert_eq!(*err.url.await.unwrap(), resource_url); + let err = &*err_vc.await?; + assert!(matches!(*err.kind.await?, FetchErrorKind::Status(404))); + assert_eq!(*err.url.await?, resource_url); let issue = err_vc.to_issue(IssueSeverity::Error.into(), get_issue_context()); - assert_eq!(*issue.severity().await.unwrap(), IssueSeverity::Error); + assert_eq!(*issue.severity().await?, IssueSeverity::Error); assert_eq!( - *issue.description().await.unwrap().unwrap().await.unwrap(), + *issue.description().await?.unwrap().await?, StyledString::Text( format!( "Received response with status 404 when requesting {}", @@ -152,8 +156,10 @@ async fn errors_on_404() { .into() ) ); + anyhow::Ok(()) }) .await + .unwrap() } fn get_issue_context() -> Vc { diff --git a/turbopack/crates/turbo-tasks-macros-tests/tests/task_input.rs b/turbopack/crates/turbo-tasks-macros-tests/tests/task_input.rs index 143592a2514d3..fbf465369095e 100644 --- a/turbopack/crates/turbo-tasks-macros-tests/tests/task_input.rs +++ b/turbopack/crates/turbo-tasks-macros-tests/tests/task_input.rs @@ -19,11 +19,13 @@ async fn one_unnamed_field(input: OneUnnamedField) -> Vc { #[tokio::test] async fn tests() { - run(®ISTRATION, async { + run(®ISTRATION, || async { assert!(ReadRef::ptr_eq( - &one_unnamed_field(OneUnnamedField(42)).await.unwrap(), - &Completion::immutable().await.unwrap(), - )) + &one_unnamed_field(OneUnnamedField(42)).await?, + &Completion::immutable().await?, + )); + anyhow::Ok(()) }) .await + .unwrap() } diff --git a/turbopack/crates/turbo-tasks-macros-tests/tests/value_debug.rs b/turbopack/crates/turbo-tasks-macros-tests/tests/value_debug.rs index 317912a60e075..e3f49c479a272 100644 --- a/turbopack/crates/turbo-tasks-macros-tests/tests/value_debug.rs +++ b/turbopack/crates/turbo-tasks-macros-tests/tests/value_debug.rs @@ -17,16 +17,14 @@ async fn ignored_indexes() { i32, ); - run(®ISTRATION, async { + run(®ISTRATION, || async { let input = IgnoredIndexes(-1, 2, -3); - let debug = input - .value_debug_format(usize::MAX) - .try_to_string() - .await - .unwrap(); + let debug = input.value_debug_format(usize::MAX).try_to_string().await?; assert!(!debug.contains("-1")); assert!(debug.contains('2')); assert!(!debug.contains("-3")); + anyhow::Ok(()) }) - .await; + .await + .unwrap(); } diff --git a/turbopack/crates/turbo-tasks-testing/src/lib.rs b/turbopack/crates/turbo-tasks-testing/src/lib.rs index 2ba3575f88963..f15697a4b4c08 100644 --- a/turbopack/crates/turbo-tasks-testing/src/lib.rs +++ b/turbopack/crates/turbo-tasks-testing/src/lib.rs @@ -24,7 +24,7 @@ use turbo_tasks::{ TurboTasksCallApi, }; -pub use crate::run::{run, Registration}; +pub use crate::run::{run, run_without_cache_check, Registration}; enum Task { Spawned(Event), diff --git a/turbopack/crates/turbo-tasks-testing/src/run.rs b/turbopack/crates/turbo-tasks-testing/src/run.rs index ef6b9ac89f9a2..c405af0c37f4c 100644 --- a/turbopack/crates/turbo-tasks-testing/src/run.rs +++ b/turbopack/crates/turbo-tasks-testing/src/run.rs @@ -1,8 +1,10 @@ use std::{ + fmt::Debug, future::Future, sync::{Arc, OnceLock}, }; +use anyhow::Result; use turbo_tasks::{run_once, trace::TraceRawVcs, TurboTasksApi}; pub struct Registration { @@ -58,7 +60,10 @@ macro_rules! register { }}; } -pub async fn run(registration: &Registration, fut: impl Future + Send + 'static) -> T +pub async fn run_without_cache_check( + registration: &Registration, + fut: impl Future + Send + 'static, +) -> T where T: TraceRawVcs + Send + 'static, { @@ -66,3 +71,22 @@ where let tt = registration.create_turbo_tasks(); run_once(tt, async move { Ok(fut.await) }).await.unwrap() } + +pub async fn run( + registration: &Registration, + fut: impl Fn() -> F + Send + 'static, +) -> Result<()> +where + F: Future> + Send + 'static, + T: Debug + PartialEq + Eq + TraceRawVcs + Send + 'static, +{ + registration.ensure_registered(); + let tt = registration.create_turbo_tasks(); + let first = run_once(tt.clone(), fut()).await?; + let second = run_once(tt, fut()).await?; + assert_eq!(first, second); + let tt = registration.create_turbo_tasks(); + let third = run_once(tt, fut()).await?; + assert_eq!(first, third); + Ok(()) +} diff --git a/turbopack/crates/turbo-tasks-testing/tests/all_in_one.rs b/turbopack/crates/turbo-tasks-testing/tests/all_in_one.rs index 91f2cf36980af..e8f53d592e3d5 100644 --- a/turbopack/crates/turbo-tasks-testing/tests/all_in_one.rs +++ b/turbopack/crates/turbo-tasks-testing/tests/all_in_one.rs @@ -8,7 +8,7 @@ static REGISTRATION: Registration = register!(); #[tokio::test] async fn all_in_one() { - run(®ISTRATION, async { + run(®ISTRATION, || async { let a: Vc = Vc::cell(4242); assert_eq!(*a.await?, 4242); diff --git a/turbopack/crates/turbo-tasks-testing/tests/call_types.rs b/turbopack/crates/turbo-tasks-testing/tests/call_types.rs index 6870d396e64f1..41ebeafe265bc 100644 --- a/turbopack/crates/turbo-tasks-testing/tests/call_types.rs +++ b/turbopack/crates/turbo-tasks-testing/tests/call_types.rs @@ -8,7 +8,7 @@ static REGISTRATION: Registration = register!(); #[tokio::test] async fn functions() { - run(®ISTRATION, async { + run(®ISTRATION, || async { assert_eq!(*fn_plain().await?, 42); assert_eq!(*fn_arg(43).await?, 43); assert_eq!(*fn_vc_arg(Vc::cell(44)).await?, 44); @@ -53,7 +53,7 @@ async fn async_fn_vc_arg(n: Vc) -> Result> { #[tokio::test] async fn methods() { - run(®ISTRATION, async { + run(®ISTRATION, || async { assert_eq!(*Value::static_method().await?, 42); assert_eq!(*Value::async_static_method().await?, 42); @@ -106,7 +106,7 @@ impl Value { #[tokio::test] async fn trait_methods() { - run(®ISTRATION, async { + run(®ISTRATION, || async { assert_eq!(*Value::static_trait_method().await?, 42); assert_eq!(*Value::async_static_trait_method().await?, 42); diff --git a/turbopack/crates/turbo-tasks-testing/tests/collectibles.rs b/turbopack/crates/turbo-tasks-testing/tests/collectibles.rs index 2bf0b392117ab..d2f05a678a751 100644 --- a/turbopack/crates/turbo-tasks-testing/tests/collectibles.rs +++ b/turbopack/crates/turbo-tasks-testing/tests/collectibles.rs @@ -12,7 +12,7 @@ static REGISTRATION: Registration = register!(); #[tokio::test] async fn transitive_emitting() { - run(®ISTRATION, async { + run(®ISTRATION, || async { let result = my_transitive_emitting_function("".into(), "".into()); result.strongly_consistent().await?; let list = result.peek_collectibles::>(); @@ -30,7 +30,7 @@ async fn transitive_emitting() { #[tokio::test] async fn transitive_emitting_indirect() { - run(®ISTRATION, async { + run(®ISTRATION, || async { let result = my_transitive_emitting_function("".into(), "".into()); let collectibles = my_transitive_emitting_function_collectibles("".into(), "".into()); let list = collectibles.strongly_consistent().await?; @@ -48,7 +48,7 @@ async fn transitive_emitting_indirect() { #[tokio::test] async fn multi_emitting() { - run(®ISTRATION, async { + run(®ISTRATION, || async { let result = my_multi_emitting_function(); result.strongly_consistent().await?; let list = result.peek_collectibles::>(); @@ -66,7 +66,7 @@ async fn multi_emitting() { #[tokio::test] async fn taking_collectibles() { - run(®ISTRATION, async { + run(®ISTRATION, || async { let result = my_collecting_function(); let list = result.take_collectibles::>(); // my_collecting_function already processed the collectibles so the list should @@ -81,7 +81,7 @@ async fn taking_collectibles() { #[tokio::test] async fn taking_collectibles_extra_layer() { - run(®ISTRATION, async { + run(®ISTRATION, || async { let result = my_collecting_function_indirect(); result.strongly_consistent().await?; let list = result.take_collectibles::>(); @@ -97,7 +97,7 @@ async fn taking_collectibles_extra_layer() { #[tokio::test] async fn taking_collectibles_parallel() { - run(®ISTRATION, async { + run(®ISTRATION, || async { let result = my_transitive_emitting_function("".into(), "a".into()); result.strongly_consistent().await?; let list = result.take_collectibles::>(); diff --git a/turbopack/crates/turbo-tasks-testing/tests/debug.rs b/turbopack/crates/turbo-tasks-testing/tests/debug.rs index 42b5366ddd8a4..bb0b96ec36ef1 100644 --- a/turbopack/crates/turbo-tasks-testing/tests/debug.rs +++ b/turbopack/crates/turbo-tasks-testing/tests/debug.rs @@ -9,91 +9,107 @@ static REGISTRATION: Registration = register!(); #[tokio::test] async fn primitive_debug() { - run(®ISTRATION, async { + run(®ISTRATION, || async { let a: Vc = Vc::cell(42); - assert_eq!(format!("{:?}", a.dbg().await.unwrap()), "42"); + assert_eq!(format!("{:?}", a.dbg().await?), "42"); + anyhow::Ok(()) }) .await + .unwrap() } #[tokio::test] async fn transparent_debug() { - run(®ISTRATION, async { + run(®ISTRATION, || async { let a: Vc = Transparent(42).cell(); - assert_eq!(format!("{:?}", a.dbg().await.unwrap()), "42"); + assert_eq!(format!("{:?}", a.dbg().await?), "42"); + + anyhow::Ok(()) }) .await + .unwrap() } #[tokio::test] async fn enum_none_debug() { - run(®ISTRATION, async { + run(®ISTRATION, || async { let a: Vc = Enum::None.cell(); - assert_eq!(format!("{:?}", a.dbg().await.unwrap()), "Enum :: None"); + assert_eq!(format!("{:?}", a.dbg().await?), "Enum :: None"); + + anyhow::Ok(()) }) .await + .unwrap() } #[tokio::test] async fn enum_transparent_debug() { - run(®ISTRATION, async { + run(®ISTRATION, || async { let a: Vc = Enum::Transparent(Transparent(42).cell()).cell(); assert_eq!( - format!("{:?}", a.dbg().await.unwrap()), + format!("{:?}", a.dbg().await?), r#"Enum :: Transparent( 42, )"# ); + anyhow::Ok(()) }) .await + .unwrap() } #[tokio::test] async fn enum_inner_vc_debug() { - run(®ISTRATION, async { + run(®ISTRATION, || async { let a: Vc = Enum::Enum(Enum::None.cell()).cell(); assert_eq!( - format!("{:?}", a.dbg().await.unwrap()), + format!("{:?}", a.dbg().await?), r#"Enum :: Enum( Enum :: None, )"# ); + anyhow::Ok(()) }) .await + .unwrap() } #[tokio::test] async fn struct_unit_debug() { - run(®ISTRATION, async { + run(®ISTRATION, || async { let a: Vc = StructUnit.cell(); - assert_eq!(format!("{:?}", a.dbg().await.unwrap()), "StructUnit"); + assert_eq!(format!("{:?}", a.dbg().await?), "StructUnit"); + anyhow::Ok(()) }) .await + .unwrap() } #[tokio::test] async fn struct_transparent_debug() { - run(®ISTRATION, async { + run(®ISTRATION, || async { let a: Vc = StructWithTransparent { transparent: Transparent(42).cell(), } .cell(); assert_eq!( - format!("{:?}", a.dbg().await.unwrap()), + format!("{:?}", a.dbg().await?), r#"StructWithTransparent { transparent: 42, }"# ); + anyhow::Ok(()) }) .await + .unwrap() } #[tokio::test] async fn struct_vec_debug() { - run(®ISTRATION, async { + run(®ISTRATION, || async { let a: Vc = StructWithVec { vec: vec![] }.cell(); assert_eq!( - format!("{:?}", a.dbg().await.unwrap()), + format!("{:?}", a.dbg().await?), r#"StructWithVec { vec: [], }"# @@ -104,33 +120,37 @@ async fn struct_vec_debug() { } .cell(); assert_eq!( - format!("{:?}", b.dbg().await.unwrap()), + format!("{:?}", b.dbg().await?), r#"StructWithVec { vec: [ 42, ], }"# ); + anyhow::Ok(()) }) .await + .unwrap() } #[tokio::test] async fn struct_ignore_debug() { - run(®ISTRATION, async { + run(®ISTRATION, || async { let a: Vc = StructWithIgnore { dont_ignore: 42, ignore: Mutex::new(()), } .cell(); assert_eq!( - format!("{:?}", a.dbg().await.unwrap()), + format!("{:?}", a.dbg().await?), r#"StructWithIgnore { dont_ignore: 42, }"# ); + anyhow::Ok(()) }) .await + .unwrap() } #[turbo_tasks::value(transparent, shared)] diff --git a/turbopack/crates/turbo-tasks-testing/tests/dirty_in_progress.rs b/turbopack/crates/turbo-tasks-testing/tests/dirty_in_progress.rs index 6f67cdc0b45b5..d0b5d21c35a05 100644 --- a/turbopack/crates/turbo-tasks-testing/tests/dirty_in_progress.rs +++ b/turbopack/crates/turbo-tasks-testing/tests/dirty_in_progress.rs @@ -10,7 +10,7 @@ static REGISTRATION: Registration = register!(); #[tokio::test] async fn dirty_in_progress() { - run(®ISTRATION, async { + run(®ISTRATION, || async { let cases = [ (1, 3, 2, 2, ""), (11, 13, 12, 42, "12"), @@ -25,20 +25,22 @@ async fn dirty_in_progress() { state: State::new(a), } .cell(); - let input_val = input.await.unwrap(); + let input_val = input.await?; let output = compute(input); - output.await.unwrap(); + output.await?; println!("update to {}", b); input_val.state.set(b); tokio::time::sleep(Duration::from_millis(100)).await; println!("update to {}", c); input_val.state.set(c); - let read = output.strongly_consistent().await.unwrap(); + let read = output.strongly_consistent().await?; assert_eq!(read.value, value); assert_eq!(read.collectible, collectible); } + anyhow::Ok(()) }) .await + .unwrap() } #[turbo_tasks::value] diff --git a/turbopack/crates/turbo-tasks-testing/tests/emptied_cells.rs b/turbopack/crates/turbo-tasks-testing/tests/emptied_cells.rs index 326636c709b54..e2b1624eb4298 100644 --- a/turbopack/crates/turbo-tasks-testing/tests/emptied_cells.rs +++ b/turbopack/crates/turbo-tasks-testing/tests/emptied_cells.rs @@ -8,35 +8,38 @@ static REGISTRATION: Registration = register!(); #[tokio::test] async fn recompute() { - run(®ISTRATION, async { + run(®ISTRATION, || async { let input = ChangingInput { state: State::new(1), } .cell(); let output = compute(input); - assert_eq!(*output.await.unwrap(), 1); + assert_eq!(*output.await?, 1); println!("changing input"); - input.await.unwrap().state.set(10); - assert_eq!(*output.strongly_consistent().await.unwrap(), 10); + input.await?.state.set(10); + assert_eq!(*output.strongly_consistent().await?, 10); println!("changing input"); - input.await.unwrap().state.set(5); - assert_eq!(*output.strongly_consistent().await.unwrap(), 5); + input.await?.state.set(5); + assert_eq!(*output.strongly_consistent().await?, 5); println!("changing input"); - input.await.unwrap().state.set(20); - assert_eq!(*output.strongly_consistent().await.unwrap(), 20); + input.await?.state.set(20); + assert_eq!(*output.strongly_consistent().await?, 20); println!("changing input"); - input.await.unwrap().state.set(15); - assert_eq!(*output.strongly_consistent().await.unwrap(), 15); + input.await?.state.set(15); + assert_eq!(*output.strongly_consistent().await?, 15); println!("changing input"); - input.await.unwrap().state.set(1); - assert_eq!(*output.strongly_consistent().await.unwrap(), 1); + input.await?.state.set(1); + assert_eq!(*output.strongly_consistent().await?, 1); + + anyhow::Ok(()) }) .await + .unwrap(); } #[turbo_tasks::value] diff --git a/turbopack/crates/turbo-tasks-testing/tests/generics.rs b/turbopack/crates/turbo-tasks-testing/tests/generics.rs index b3e8990ba4031..a0748364dac38 100644 --- a/turbopack/crates/turbo-tasks-testing/tests/generics.rs +++ b/turbopack/crates/turbo-tasks-testing/tests/generics.rs @@ -10,123 +10,138 @@ static REGISTRATION: Registration = register!(); #[tokio::test] async fn test_option_some() { - run(®ISTRATION, async move { + run(®ISTRATION, || async move { let vc_42 = Vc::cell(42); let option: Vc>> = Vc::cell(Some(vc_42)); - assert!(*option.is_some().await.unwrap()); - assert!(!(*option.is_none().await.unwrap())); - assert_eq!(&*option.await.unwrap(), &Some(vc_42)); - assert_eq!(option.dbg().await.unwrap().to_string(), "Some(\n 42,\n)"); + assert!(*option.is_some().await?); + assert!(!(*option.is_none().await?)); + assert_eq!(&*option.await?, &Some(vc_42)); + assert_eq!(option.dbg().await?.to_string(), "Some(\n 42,\n)"); + anyhow::Ok(()) }) .await + .unwrap() } #[tokio::test] async fn test_option_none() { - run(®ISTRATION, async move { + run(®ISTRATION, || async move { let option: Vc>> = Default::default(); - assert!(!(*option.is_some().await.unwrap())); - assert!(*option.is_none().await.unwrap()); - assert_eq!(&*option.await.unwrap(), &None); - assert_eq!(option.dbg().await.unwrap().to_string(), "None"); + assert!(!(*option.is_some().await?)); + assert!(*option.is_none().await?); + assert_eq!(&*option.await?, &None); + assert_eq!(option.dbg().await?.to_string(), "None"); + anyhow::Ok(()) }) .await + .unwrap() } #[tokio::test] async fn test_vec() { - run(®ISTRATION, async move { + run(®ISTRATION, || async move { let vc_42 = Vc::cell(42); let vec: Vc>> = Vc::cell(vec![vc_42]); - assert_eq!(*vec.len().await.unwrap(), 1); - assert!(!(*vec.is_empty().await.unwrap())); - assert_eq!(&*vec.await.unwrap(), &[vc_42]); - assert_eq!(vec.dbg().await.unwrap().to_string(), "[\n 42,\n]"); + assert_eq!(*vec.len().await?, 1); + assert!(!(*vec.is_empty().await?)); + assert_eq!(&*vec.await?, &[vc_42]); + assert_eq!(vec.dbg().await?.to_string(), "[\n 42,\n]"); + anyhow::Ok(()) }) .await + .unwrap() } #[tokio::test] async fn test_empty_vec() { - run(®ISTRATION, async move { + run(®ISTRATION, || async move { let vec: Vc>> = Default::default(); - assert_eq!(*vec.len().await.unwrap(), 0); - assert!(*vec.is_empty().await.unwrap()); - assert_eq!(vec.dbg().await.unwrap().to_string(), "[]"); + assert_eq!(*vec.len().await?, 0); + assert!(*vec.is_empty().await?); + assert_eq!(vec.dbg().await?.to_string(), "[]"); + anyhow::Ok(()) }) .await + .unwrap() } #[tokio::test] async fn test_nested_empty_vec() { - run(®ISTRATION, async move { + run(®ISTRATION, || async move { let vec: Vc>>>> = Default::default(); - assert_eq!(*vec.len().await.unwrap(), 0); - assert_eq!(vec.dbg().await.unwrap().to_string(), "[]"); + assert_eq!(*vec.len().await?, 0); + assert_eq!(vec.dbg().await?.to_string(), "[]"); + anyhow::Ok(()) }) .await + .unwrap() } #[tokio::test] async fn test_index_set() { - run(®ISTRATION, async move { + run(®ISTRATION, || async move { let vc_42 = Vc::cell(42); let set: Vc>> = Vc::cell(IndexSet::from([vc_42])); - assert_eq!(*set.len().await.unwrap(), 1); - assert!(!(*set.is_empty().await.unwrap())); - assert_eq!(&*set.await.unwrap(), &IndexSet::from([vc_42])); - assert_eq!(set.dbg().await.unwrap().to_string(), "{\n 42,\n}"); + assert_eq!(*set.len().await?, 1); + assert!(!(*set.is_empty().await?)); + assert_eq!(&*set.await?, &IndexSet::from([vc_42])); + assert_eq!(set.dbg().await?.to_string(), "{\n 42,\n}"); + anyhow::Ok(()) }) .await + .unwrap() } #[tokio::test] async fn test_empty_index_set() { - run(®ISTRATION, async move { + run(®ISTRATION, || async move { let set: Vc>> = Default::default(); - assert_eq!(*set.len().await.unwrap(), 0); - assert!(*set.is_empty().await.unwrap()); - assert_eq!(&*set.await.unwrap(), &IndexSet::>::default()); - assert_eq!(set.dbg().await.unwrap().to_string(), "{}"); + assert_eq!(*set.len().await?, 0); + assert!(*set.is_empty().await?); + assert_eq!(&*set.await?, &IndexSet::>::default()); + assert_eq!(set.dbg().await?.to_string(), "{}"); + anyhow::Ok(()) }) .await + .unwrap() } #[tokio::test] async fn test_index_map() { - run(®ISTRATION, async move { + run(®ISTRATION, || async move { let vc_42 = Vc::cell(42); let map: Vc, _>> = Vc::cell(IndexMap::from([(vc_42, vc_42)])); - assert_eq!(*map.len().await.unwrap(), 1); - assert!(!(*map.is_empty().await.unwrap())); - assert_eq!(&*map.await.unwrap(), &IndexMap::from([(vc_42, vc_42)])); - assert_eq!(map.dbg().await.unwrap().to_string(), "{\n 42: 42,\n}"); + assert_eq!(*map.len().await?, 1); + assert!(!(*map.is_empty().await?)); + assert_eq!(&*map.await?, &IndexMap::from([(vc_42, vc_42)])); + assert_eq!(map.dbg().await?.to_string(), "{\n 42: 42,\n}"); + anyhow::Ok(()) }) .await + .unwrap() } #[tokio::test] async fn test_empty_index_map() { - run(®ISTRATION, async move { + run(®ISTRATION, || async move { let map: Vc, Vc>> = Default::default(); - assert_eq!(*map.len().await.unwrap(), 0); - assert!(*map.is_empty().await.unwrap()); - assert_eq!( - &*map.await.unwrap(), - &IndexMap::, Vc>::default() - ); - assert_eq!(map.dbg().await.unwrap().to_string(), "{}"); + assert_eq!(*map.len().await?, 0); + assert!(*map.is_empty().await?); + assert_eq!(&*map.await?, &IndexMap::, Vc>::default()); + assert_eq!(map.dbg().await?.to_string(), "{}"); + anyhow::Ok(()) }) .await + .unwrap() } // Simulate a non-deterministic function that stores different generic types in // it's cells each time it runs. #[tokio::test] async fn test_changing_generic() { - run(®ISTRATION, async move { + run(®ISTRATION, || async move { let state_vc = State::default().cell(); - let state_ref = state_vc.await.unwrap(); + let state_ref = state_vc.await?; for _i in 0..10 { let _ = non_deterministic(state_vc) .resolve_strongly_consistent() @@ -141,18 +156,22 @@ async fn test_changing_generic() { .unwrap() .invalidate(); } + anyhow::Ok(()) }) .await + .unwrap() } // Test that we can convert a `Vc` to a `ReadRef`, and then back to a `Vc`. #[tokio::test] async fn test_read_ref_round_trip() { - run(®ISTRATION, async move { + run(®ISTRATION, || async move { let c: Vc>> = Vc::cell(Some(Vc::cell(1))); - let _ = ReadRef::cell(c.await.unwrap()).await.unwrap(); + let _ = ReadRef::cell(c.await?).await?; + anyhow::Ok(()) }) .await + .unwrap() } #[turbo_tasks::value(eq = "manual")] diff --git a/turbopack/crates/turbo-tasks-testing/tests/read_ref_cell.rs b/turbopack/crates/turbo-tasks-testing/tests/read_ref_cell.rs index 6266d3c56fe5d..90144fb942d38 100644 --- a/turbopack/crates/turbo-tasks-testing/tests/read_ref_cell.rs +++ b/turbopack/crates/turbo-tasks-testing/tests/read_ref_cell.rs @@ -10,7 +10,7 @@ static REGISTRATION: Registration = register!(); #[tokio::test] async fn read_ref() { - run(®ISTRATION, async { + run(®ISTRATION, || async { let counter = Counter::cell(Counter { value: Mutex::new((0, None)), }); diff --git a/turbopack/crates/turbo-tasks-testing/tests/recompute.rs b/turbopack/crates/turbo-tasks-testing/tests/recompute.rs index 976efd03e66b7..cf87bfb97e6ee 100644 --- a/turbopack/crates/turbo-tasks-testing/tests/recompute.rs +++ b/turbopack/crates/turbo-tasks-testing/tests/recompute.rs @@ -8,7 +8,7 @@ static REGISTRATION: Registration = register!(); #[tokio::test] async fn recompute() { - run(®ISTRATION, async { + run(®ISTRATION, || async { let input = ChangingInput { state: State::new(1), } diff --git a/turbopack/crates/turbo-tasks-testing/tests/recompute_collectibles.rs b/turbopack/crates/turbo-tasks-testing/tests/recompute_collectibles.rs index 07391c207a703..a91c0225ac193 100644 --- a/turbopack/crates/turbo-tasks-testing/tests/recompute_collectibles.rs +++ b/turbopack/crates/turbo-tasks-testing/tests/recompute_collectibles.rs @@ -8,24 +8,26 @@ static REGISTRATION: Registration = register!(); #[tokio::test] async fn recompute() { - run(®ISTRATION, async { + run(®ISTRATION, || async { let input = ChangingInput { state: State::new(1), } .cell(); let output = compute(input, 100); - let read = output.await.unwrap(); + let read = output.await?; assert_eq!(read.value, 42); assert_eq!(read.collectible, "1"); for i in 2..100 { - input.await.unwrap().state.set(i); - let read = output.strongly_consistent().await.unwrap(); + input.await?.state.set(i); + let read = output.strongly_consistent().await?; assert_eq!(read.value, 42); assert_eq!(read.collectible, i.to_string()); } + anyhow::Ok(()) }) .await + .unwrap() } #[turbo_tasks::value] diff --git a/turbopack/crates/turbo-tasks-testing/tests/trait_ref_cell.rs b/turbopack/crates/turbo-tasks-testing/tests/trait_ref_cell.rs index cfde0d3f4d828..7d81569628b8c 100644 --- a/turbopack/crates/turbo-tasks-testing/tests/trait_ref_cell.rs +++ b/turbopack/crates/turbo-tasks-testing/tests/trait_ref_cell.rs @@ -10,7 +10,7 @@ static REGISTRATION: Registration = register!(); #[tokio::test] async fn trait_ref() { - run(®ISTRATION, async { + run(®ISTRATION, || async { let counter = Counter::cell(Counter { value: Mutex::new((0, None)), });