Unverified Commit be76b0cf authored by Luke Sandberg's avatar Luke Sandberg Committed by GitHub

test(turbopack): strongly read test operations (#98247)

## Summary

Replace top-level consistency suppression in straightforward backend
tests with local operation roots that are read strongly consistently.
Inner operation functions keep each migration scoped to its test.

## Verification

- `cargo test -p turbo-tasks-backend --test filter_unused_args --test
panics --test task_statistics`
- `cargo fmt --all -- --check`

<!-- NEXT_JS_LLM -->

<!-- fleet 475180cd-06a7-4669-89b5-a2029a3a18c9 -->

---------
Co-authored-by: 's avatarvercel-fleet-prod[bot] <318278635+vercel-fleet-prod[bot]@users.noreply.github.com>
Co-authored-by: 's avatarLuke Sandberg <210140+lukesandberg@users.noreply.github.com>
parent 975b9cff
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
#![allow(clippy::needless_return)] // tokio macro-generated code doesn't respect this #![allow(clippy::needless_return)] // tokio macro-generated code doesn't respect this
use anyhow::Result; use anyhow::Result;
use turbo_tasks::{Vc, unmark_top_level_task_may_leak_eventually_consistent_state}; use turbo_tasks::Vc;
use turbo_tasks_testing::{Registration, register, run_once}; use turbo_tasks_testing::{Registration, register, run_once};
static REGISTRATION: Registration = register!(); static REGISTRATION: Registration = register!();
...@@ -11,8 +11,8 @@ static REGISTRATION: Registration = register!(); ...@@ -11,8 +11,8 @@ static REGISTRATION: Registration = register!();
#[tokio::test(flavor = "multi_thread", worker_threads = 2)] #[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_filtered_impl_method_args() -> Result<()> { async fn test_filtered_impl_method_args() -> Result<()> {
run_once(&REGISTRATION, async || { run_once(&REGISTRATION, async || {
unmark_top_level_task_may_leak_eventually_consistent_state(); #[turbo_tasks::function(operation, root)]
async fn operation() -> Result<Vc<()>> {
let uses_arg = UsesArg(0).cell(); let uses_arg = UsesArg(0).cell();
assert_eq!( assert_eq!(
uses_arg.method_with_arg(0).to_resolved().await?, uses_arg.method_with_arg(0).to_resolved().await?,
...@@ -33,6 +33,10 @@ async fn test_filtered_impl_method_args() -> Result<()> { ...@@ -33,6 +33,10 @@ async fn test_filtered_impl_method_args() -> Result<()> {
ignores_arg.method_with_arg(1).to_resolved().await?, ignores_arg.method_with_arg(1).to_resolved().await?,
); );
Ok(Vc::cell(()))
}
operation().read_strongly_consistent().await?;
Ok(()) Ok(())
}) })
.await .await
...@@ -41,8 +45,8 @@ async fn test_filtered_impl_method_args() -> Result<()> { ...@@ -41,8 +45,8 @@ async fn test_filtered_impl_method_args() -> Result<()> {
#[tokio::test(flavor = "multi_thread", worker_threads = 2)] #[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_filtered_trait_method_args() -> Result<()> { async fn test_filtered_trait_method_args() -> Result<()> {
run_once(&REGISTRATION, async || { run_once(&REGISTRATION, async || {
unmark_top_level_task_may_leak_eventually_consistent_state(); #[turbo_tasks::function(operation, root)]
async fn operation() -> Result<Vc<()>> {
let uses_arg = UsesArg(0).cell(); let uses_arg = UsesArg(0).cell();
assert_eq!( assert_eq!(
uses_arg.trait_method_with_arg(0).to_resolved().await?, uses_arg.trait_method_with_arg(0).to_resolved().await?,
...@@ -63,6 +67,10 @@ async fn test_filtered_trait_method_args() -> Result<()> { ...@@ -63,6 +67,10 @@ async fn test_filtered_trait_method_args() -> Result<()> {
ignores_arg.trait_method_with_arg(1).to_resolved().await?, ignores_arg.trait_method_with_arg(1).to_resolved().await?,
); );
Ok(Vc::cell(()))
}
operation().read_strongly_consistent().await?;
Ok(()) Ok(())
}) })
.await .await
...@@ -71,8 +79,8 @@ async fn test_filtered_trait_method_args() -> Result<()> { ...@@ -71,8 +79,8 @@ async fn test_filtered_trait_method_args() -> Result<()> {
#[tokio::test(flavor = "multi_thread", worker_threads = 2)] #[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_filtered_impl_method_self() -> Result<()> { async fn test_filtered_impl_method_self() -> Result<()> {
run_once(&REGISTRATION, async || { run_once(&REGISTRATION, async || {
unmark_top_level_task_may_leak_eventually_consistent_state(); #[turbo_tasks::function(operation, root)]
async fn operation() -> Result<Vc<()>> {
let uses_arg = UsesArg(0).cell(); let uses_arg = UsesArg(0).cell();
let uses_arg2 = UsesArg(1).cell(); let uses_arg2 = UsesArg(1).cell();
assert_eq!( assert_eq!(
...@@ -99,6 +107,10 @@ async fn test_filtered_impl_method_self() -> Result<()> { ...@@ -99,6 +107,10 @@ async fn test_filtered_impl_method_self() -> Result<()> {
ignores_arg2.method_with_arg(1).to_resolved().await?, ignores_arg2.method_with_arg(1).to_resolved().await?,
); );
Ok(Vc::cell(()))
}
operation().read_strongly_consistent().await?;
Ok(()) Ok(())
}) })
.await .await
...@@ -107,8 +119,8 @@ async fn test_filtered_impl_method_self() -> Result<()> { ...@@ -107,8 +119,8 @@ async fn test_filtered_impl_method_self() -> Result<()> {
#[tokio::test(flavor = "multi_thread", worker_threads = 2)] #[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_filtered_trait_method_self() -> Result<()> { async fn test_filtered_trait_method_self() -> Result<()> {
run_once(&REGISTRATION, async || { run_once(&REGISTRATION, async || {
unmark_top_level_task_may_leak_eventually_consistent_state(); #[turbo_tasks::function(operation, root)]
async fn operation() -> Result<Vc<()>> {
let uses_arg = UsesArg(0).cell(); let uses_arg = UsesArg(0).cell();
let uses_arg2 = UsesArg(1).cell(); let uses_arg2 = UsesArg(1).cell();
assert_eq!( assert_eq!(
...@@ -135,6 +147,10 @@ async fn test_filtered_trait_method_self() -> Result<()> { ...@@ -135,6 +147,10 @@ async fn test_filtered_trait_method_self() -> Result<()> {
ignores_arg2.trait_method_with_arg(1).to_resolved().await?, ignores_arg2.trait_method_with_arg(1).to_resolved().await?,
); );
Ok(Vc::cell(()))
}
operation().read_strongly_consistent().await?;
Ok(()) Ok(())
}) })
.await .await
...@@ -143,8 +159,8 @@ async fn test_filtered_trait_method_self() -> Result<()> { ...@@ -143,8 +159,8 @@ async fn test_filtered_trait_method_self() -> Result<()> {
#[tokio::test(flavor = "multi_thread", worker_threads = 2)] #[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_filtered_plain_method_args() -> Result<()> { async fn test_filtered_plain_method_args() -> Result<()> {
run_once(&REGISTRATION, async || { run_once(&REGISTRATION, async || {
unmark_top_level_task_may_leak_eventually_consistent_state(); #[turbo_tasks::function(operation, root)]
async fn operation() -> Result<Vc<()>> {
assert_eq!( assert_eq!(
method_with_arg(0).to_resolved().await?, method_with_arg(0).to_resolved().await?,
method_with_arg(0).to_resolved().await?, method_with_arg(0).to_resolved().await?,
...@@ -162,6 +178,10 @@ async fn test_filtered_plain_method_args() -> Result<()> { ...@@ -162,6 +178,10 @@ async fn test_filtered_plain_method_args() -> Result<()> {
method_with_ignored_arg(1).to_resolved().await?, method_with_ignored_arg(1).to_resolved().await?,
); );
Ok(Vc::cell(()))
}
operation().read_strongly_consistent().await?;
Ok(()) Ok(())
}) })
.await .await
......
...@@ -13,7 +13,6 @@ use turbo_tasks::{ ...@@ -13,7 +13,6 @@ use turbo_tasks::{
Vc, Vc,
backend::TurboTasksExecutionError, backend::TurboTasksExecutionError,
panic_hooks::{handle_panic, register_panic_hook}, panic_hooks::{handle_panic, register_panic_hook},
unmark_top_level_task_may_leak_eventually_consistent_state,
}; };
use turbo_tasks_testing::{Registration, register, run_once_without_cache_check}; use turbo_tasks_testing::{Registration, register, run_once_without_cache_check};
...@@ -41,8 +40,15 @@ async fn test_panic_hook() { ...@@ -41,8 +40,15 @@ async fn test_panic_hook() {
}); });
let result = run_once_without_cache_check(&REGISTRATION, async move { let result = run_once_without_cache_check(&REGISTRATION, async move {
unmark_top_level_task_may_leak_eventually_consistent_state(); #[turbo_tasks::function(operation, root)]
anyhow::Ok(*double(3).await?) fn operation() -> Vc<u64> {
double(3)
}
operation()
.read_strongly_consistent()
.await
.map(|value| *value)
}) })
.await; .await;
......
...@@ -6,7 +6,7 @@ use std::future::IntoFuture; ...@@ -6,7 +6,7 @@ use std::future::IntoFuture;
use anyhow::Result; use anyhow::Result;
use serde_json::json; use serde_json::json;
use turbo_tasks::{Vc, unmark_top_level_task_may_leak_eventually_consistent_state}; use turbo_tasks::Vc;
use turbo_tasks_testing::{Registration, register, run_without_cache_check}; use turbo_tasks_testing::{Registration, register, run_without_cache_check};
static REGISTRATION: Registration = register!(); static REGISTRATION: Registration = register!();
...@@ -14,7 +14,8 @@ static REGISTRATION: Registration = register!(); ...@@ -14,7 +14,8 @@ static REGISTRATION: Registration = register!();
#[tokio::test(flavor = "multi_thread", worker_threads = 2)] #[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_simple_task() -> Result<()> { async fn test_simple_task() -> Result<()> {
run_without_cache_check(&REGISTRATION, async move { run_without_cache_check(&REGISTRATION, async move {
unmark_top_level_task_may_leak_eventually_consistent_state(); #[turbo_tasks::function(operation, root)]
async fn operation() -> Result<Vc<()>> {
enable_stats(); enable_stats();
for i in 0..10 { for i in 0..10 {
double(i).await.unwrap(); double(i).await.unwrap();
...@@ -24,6 +25,10 @@ async fn test_simple_task() -> Result<()> { ...@@ -24,6 +25,10 @@ async fn test_simple_task() -> Result<()> {
for i in 0..5 { for i in 0..5 {
double(i).await.unwrap(); double(i).await.unwrap();
} }
Ok(Vc::cell(()))
}
operation().read_strongly_consistent().await?;
assert_eq!( assert_eq!(
stats_json(), stats_json(),
json!({ json!({
...@@ -41,12 +46,17 @@ async fn test_simple_task() -> Result<()> { ...@@ -41,12 +46,17 @@ async fn test_simple_task() -> Result<()> {
#[tokio::test(flavor = "multi_thread", worker_threads = 2)] #[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_await_same_vc_multiple_times() -> Result<()> { async fn test_await_same_vc_multiple_times() -> Result<()> {
run_without_cache_check(&REGISTRATION, async move { run_without_cache_check(&REGISTRATION, async move {
unmark_top_level_task_may_leak_eventually_consistent_state(); #[turbo_tasks::function(operation, root)]
async fn operation() -> Result<Vc<()>> {
enable_stats(); enable_stats();
let dvc = double(0); let dvc = double(0);
// this is awaited multiple times, but only resolved once // this is awaited multiple times, but only resolved once
tokio::try_join!(dvc.into_future(), dvc.into_future()).unwrap(); tokio::try_join!(dvc.into_future(), dvc.into_future()).unwrap();
dvc.await.unwrap(); dvc.await.unwrap();
Ok(Vc::cell(()))
}
operation().read_strongly_consistent().await?;
assert_eq!( assert_eq!(
stats_json(), stats_json(),
json!({ json!({
...@@ -64,7 +74,8 @@ async fn test_await_same_vc_multiple_times() -> Result<()> { ...@@ -64,7 +74,8 @@ async fn test_await_same_vc_multiple_times() -> Result<()> {
#[tokio::test(flavor = "multi_thread", worker_threads = 2)] #[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_vc_receiving_task() -> Result<()> { async fn test_vc_receiving_task() -> Result<()> {
run_without_cache_check(&REGISTRATION, async move { run_without_cache_check(&REGISTRATION, async move {
unmark_top_level_task_may_leak_eventually_consistent_state(); #[turbo_tasks::function(operation, root)]
async fn operation() -> Result<Vc<()>> {
enable_stats(); enable_stats();
for i in 0..10 { for i in 0..10 {
let dvc = double(i); let dvc = double(i);
...@@ -76,6 +87,10 @@ async fn test_vc_receiving_task() -> Result<()> { ...@@ -76,6 +87,10 @@ async fn test_vc_receiving_task() -> Result<()> {
let dvc = double(i); let dvc = double(i);
double_vc(dvc).await.unwrap(); double_vc(dvc).await.unwrap();
} }
Ok(Vc::cell(()))
}
operation().read_strongly_consistent().await?;
assert_eq!( assert_eq!(
stats_json(), stats_json(),
json!({ json!({
...@@ -97,12 +112,14 @@ async fn test_vc_receiving_task() -> Result<()> { ...@@ -97,12 +112,14 @@ async fn test_vc_receiving_task() -> Result<()> {
#[tokio::test(flavor = "multi_thread", worker_threads = 2)] #[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_trait_methods() -> Result<()> { async fn test_trait_methods() -> Result<()> {
run_without_cache_check(&REGISTRATION, async move { run_without_cache_check(&REGISTRATION, async move {
unmark_top_level_task_may_leak_eventually_consistent_state(); #[turbo_tasks::function(operation, root)]
async fn operation() -> Result<Vc<()>> {
enable_stats(); enable_stats();
for i in 0..10 { for i in 0..10 {
let wvc = wrap(i); let wvc = wrap(i);
tokio::try_join!(wvc.double().into_future(), wvc.double().into_future()).unwrap(); tokio::try_join!(wvc.double().into_future(), wvc.double().into_future()).unwrap();
tokio::try_join!(wvc.double_vc().into_future(), wvc.double_vc().into_future()).unwrap(); tokio::try_join!(wvc.double_vc().into_future(), wvc.double_vc().into_future())
.unwrap();
} }
// use cached results // use cached results
for i in 0..5 { for i in 0..5 {
...@@ -110,6 +127,10 @@ async fn test_trait_methods() -> Result<()> { ...@@ -110,6 +127,10 @@ async fn test_trait_methods() -> Result<()> {
wvc.double().await.unwrap(); wvc.double().await.unwrap();
wvc.double_vc().await.unwrap(); wvc.double_vc().await.unwrap();
} }
Ok(Vc::cell(()))
}
operation().read_strongly_consistent().await?;
assert_eq!( assert_eq!(
stats_json(), stats_json(),
json!({ json!({
...@@ -135,13 +156,15 @@ async fn test_trait_methods() -> Result<()> { ...@@ -135,13 +156,15 @@ async fn test_trait_methods() -> Result<()> {
#[tokio::test(flavor = "multi_thread", worker_threads = 2)] #[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_dyn_trait_methods() -> Result<()> { async fn test_dyn_trait_methods() -> Result<()> {
run_without_cache_check(&REGISTRATION, async move { run_without_cache_check(&REGISTRATION, async move {
unmark_top_level_task_may_leak_eventually_consistent_state(); #[turbo_tasks::function(operation, root)]
async fn operation() -> Result<Vc<()>> {
enable_stats(); enable_stats();
for i in 0..10 { for i in 0..10 {
let wvc: Vc<Box<dyn Doublable>> = Vc::upcast(wrap(i)); let wvc: Vc<Box<dyn Doublable>> = Vc::upcast(wrap(i));
let _ = tokio::try_join!(wvc.double().to_resolved(), wvc.double().to_resolved())
.unwrap();
let _ = let _ =
tokio::try_join!(wvc.double().to_resolved(), wvc.double().to_resolved()).unwrap(); tokio::try_join!(wvc.double_vc().to_resolved(), wvc.double_vc().to_resolved())
let _ = tokio::try_join!(wvc.double_vc().to_resolved(), wvc.double_vc().to_resolved())
.unwrap(); .unwrap();
} }
// use cached results // use cached results
...@@ -156,6 +179,10 @@ async fn test_dyn_trait_methods() -> Result<()> { ...@@ -156,6 +179,10 @@ async fn test_dyn_trait_methods() -> Result<()> {
let _ = wvc.double().await.unwrap(); let _ = wvc.double().await.unwrap();
let _ = wvc.double_vc().await.unwrap(); let _ = wvc.double_vc().await.unwrap();
} }
Ok(Vc::cell(()))
}
operation().read_strongly_consistent().await?;
assert_eq!( assert_eq!(
stats_json(), stats_json(),
json!({ json!({
...@@ -182,13 +209,18 @@ async fn test_dyn_trait_methods() -> Result<()> { ...@@ -182,13 +209,18 @@ async fn test_dyn_trait_methods() -> Result<()> {
#[tokio::test(flavor = "multi_thread", worker_threads = 2)] #[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_no_execution() -> Result<()> { async fn test_no_execution() -> Result<()> {
run_without_cache_check(&REGISTRATION, async move { run_without_cache_check(&REGISTRATION, async move {
unmark_top_level_task_may_leak_eventually_consistent_state(); #[turbo_tasks::function(operation, root)]
async fn operation() -> Result<Vc<()>> {
enable_stats(); enable_stats();
wrap_vc(double_vc(double(123))) wrap_vc(double_vc(double(123)))
.double() .double()
.double_vc() .double_vc()
.as_side_effect() .as_side_effect()
.await?; .await?;
Ok(Vc::cell(()))
}
operation().read_strongly_consistent().await?;
assert_eq!( assert_eq!(
stats_json(), stats_json(),
json!({ json!({
...@@ -222,9 +254,14 @@ async fn test_no_execution() -> Result<()> { ...@@ -222,9 +254,14 @@ async fn test_no_execution() -> Result<()> {
#[tokio::test(flavor = "multi_thread", worker_threads = 2)] #[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_inline_definitions() -> Result<()> { async fn test_inline_definitions() -> Result<()> {
run_without_cache_check(&REGISTRATION, async move { run_without_cache_check(&REGISTRATION, async move {
unmark_top_level_task_may_leak_eventually_consistent_state(); #[turbo_tasks::function(operation, root)]
async fn operation() -> Result<Vc<()>> {
enable_stats(); enable_stats();
inline_definitions().await?; inline_definitions().await?;
Ok(Vc::cell(()))
}
operation().read_strongly_consistent().await?;
assert_eq!( assert_eq!(
stats_json(), stats_json(),
json!({ json!({
......
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