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
...@@ -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,16 +14,21 @@ static REGISTRATION: Registration = register!(); ...@@ -14,16 +14,21 @@ 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)]
enable_stats(); async fn operation() -> Result<Vc<()>> {
for i in 0..10 { enable_stats();
double(i).await.unwrap(); for i in 0..10 {
// use cached results double(i).await.unwrap();
double(i).await.unwrap(); // use cached results
} double(i).await.unwrap();
for i in 0..5 { }
double(i).await.unwrap(); for i in 0..5 {
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)]
enable_stats(); async fn operation() -> Result<Vc<()>> {
let dvc = double(0); enable_stats();
// this is awaited multiple times, but only resolved once let dvc = double(0);
tokio::try_join!(dvc.into_future(), dvc.into_future()).unwrap(); // this is awaited multiple times, but only resolved once
dvc.await.unwrap(); tokio::try_join!(dvc.into_future(), dvc.into_future()).unwrap();
dvc.await.unwrap();
Ok(Vc::cell(()))
}
operation().read_strongly_consistent().await?;
assert_eq!( assert_eq!(
stats_json(), stats_json(),
json!({ json!({
...@@ -64,18 +74,23 @@ async fn test_await_same_vc_multiple_times() -> Result<()> { ...@@ -64,18 +74,23 @@ 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)]
enable_stats(); async fn operation() -> Result<Vc<()>> {
for i in 0..10 { enable_stats();
let dvc = double(i); for i in 0..10 {
double_vc(dvc).await.unwrap(); let dvc = double(i);
// use cached results double_vc(dvc).await.unwrap();
double_vc(dvc).await.unwrap(); // use cached results
} double_vc(dvc).await.unwrap();
for i in 0..5 { }
let dvc = double(i); for i in 0..5 {
double_vc(dvc).await.unwrap(); let dvc = double(i);
double_vc(dvc).await.unwrap();
}
Ok(Vc::cell(()))
} }
operation().read_strongly_consistent().await?;
assert_eq!( assert_eq!(
stats_json(), stats_json(),
json!({ json!({
...@@ -97,19 +112,25 @@ async fn test_vc_receiving_task() -> Result<()> { ...@@ -97,19 +112,25 @@ 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)]
enable_stats(); async fn operation() -> Result<Vc<()>> {
for i in 0..10 { enable_stats();
let wvc = wrap(i); for i in 0..10 {
tokio::try_join!(wvc.double().into_future(), wvc.double().into_future()).unwrap(); let wvc = wrap(i);
tokio::try_join!(wvc.double_vc().into_future(), wvc.double_vc().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())
// use cached results .unwrap();
for i in 0..5 { }
let wvc = wrap(i); // use cached results
wvc.double().await.unwrap(); for i in 0..5 {
wvc.double_vc().await.unwrap(); let wvc = wrap(i);
wvc.double().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,27 +156,33 @@ async fn test_trait_methods() -> Result<()> { ...@@ -135,27 +156,33 @@ 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)]
enable_stats(); async fn operation() -> Result<Vc<()>> {
for i in 0..10 { enable_stats();
let wvc: Vc<Box<dyn Doublable>> = Vc::upcast(wrap(i)); for i in 0..10 {
let _ = let wvc: Vc<Box<dyn Doublable>> = Vc::upcast(wrap(i));
tokio::try_join!(wvc.double().to_resolved(), wvc.double().to_resolved()).unwrap(); let _ = tokio::try_join!(wvc.double().to_resolved(), wvc.double().to_resolved())
let _ = tokio::try_join!(wvc.double_vc().to_resolved(), wvc.double_vc().to_resolved()) .unwrap();
.unwrap(); let _ =
} tokio::try_join!(wvc.double_vc().to_resolved(), wvc.double_vc().to_resolved())
// use cached results .unwrap();
for i in 0..5 { }
let wvc: Vc<Box<dyn Doublable>> = Vc::upcast(wrap(i)); // use cached results
let _ = wvc.double().to_resolved().await.unwrap(); for i in 0..5 {
let _ = wvc.double_vc().to_resolved().await.unwrap(); let wvc: Vc<Box<dyn Doublable>> = Vc::upcast(wrap(i));
} let _ = wvc.double().to_resolved().await.unwrap();
// use cached results without dynamic dispatch let _ = wvc.double_vc().to_resolved().await.unwrap();
for i in 0..2 { }
let wvc = wrap(i); // use cached results without dynamic dispatch
let _ = wvc.double().await.unwrap(); for i in 0..2 {
let _ = wvc.double_vc().await.unwrap(); let wvc = wrap(i);
let _ = wvc.double().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)]
enable_stats(); async fn operation() -> Result<Vc<()>> {
wrap_vc(double_vc(double(123))) enable_stats();
.double() wrap_vc(double_vc(double(123)))
.double_vc() .double()
.as_side_effect() .double_vc()
.await?; .as_side_effect()
.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)]
enable_stats(); async fn operation() -> Result<Vc<()>> {
inline_definitions().await?; enable_stats();
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