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::{
Vc,
backend::TurboTasksExecutionError,
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};
......@@ -41,8 +40,15 @@ async fn test_panic_hook() {
});
let result = run_once_without_cache_check(&REGISTRATION, async move {
unmark_top_level_task_may_leak_eventually_consistent_state();
anyhow::Ok(*double(3).await?)
#[turbo_tasks::function(operation, root)]
fn operation() -> Vc<u64> {
double(3)
}
operation()
.read_strongly_consistent()
.await
.map(|value| *value)
})
.await;
......
......@@ -6,7 +6,7 @@ use std::future::IntoFuture;
use anyhow::Result;
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};
static REGISTRATION: Registration = register!();
......@@ -14,16 +14,21 @@ static REGISTRATION: Registration = register!();
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_simple_task() -> Result<()> {
run_without_cache_check(&REGISTRATION, async move {
unmark_top_level_task_may_leak_eventually_consistent_state();
enable_stats();
for i in 0..10 {
double(i).await.unwrap();
// use cached results
double(i).await.unwrap();
}
for i in 0..5 {
double(i).await.unwrap();
#[turbo_tasks::function(operation, root)]
async fn operation() -> Result<Vc<()>> {
enable_stats();
for i in 0..10 {
double(i).await.unwrap();
// use cached results
double(i).await.unwrap();
}
for i in 0..5 {
double(i).await.unwrap();
}
Ok(Vc::cell(()))
}
operation().read_strongly_consistent().await?;
assert_eq!(
stats_json(),
json!({
......@@ -41,12 +46,17 @@ async fn test_simple_task() -> Result<()> {
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_await_same_vc_multiple_times() -> Result<()> {
run_without_cache_check(&REGISTRATION, async move {
unmark_top_level_task_may_leak_eventually_consistent_state();
enable_stats();
let dvc = double(0);
// this is awaited multiple times, but only resolved once
tokio::try_join!(dvc.into_future(), dvc.into_future()).unwrap();
dvc.await.unwrap();
#[turbo_tasks::function(operation, root)]
async fn operation() -> Result<Vc<()>> {
enable_stats();
let dvc = double(0);
// this is awaited multiple times, but only resolved once
tokio::try_join!(dvc.into_future(), dvc.into_future()).unwrap();
dvc.await.unwrap();
Ok(Vc::cell(()))
}
operation().read_strongly_consistent().await?;
assert_eq!(
stats_json(),
json!({
......@@ -64,18 +74,23 @@ async fn test_await_same_vc_multiple_times() -> Result<()> {
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_vc_receiving_task() -> Result<()> {
run_without_cache_check(&REGISTRATION, async move {
unmark_top_level_task_may_leak_eventually_consistent_state();
enable_stats();
for i in 0..10 {
let dvc = double(i);
double_vc(dvc).await.unwrap();
// use cached results
double_vc(dvc).await.unwrap();
}
for i in 0..5 {
let dvc = double(i);
double_vc(dvc).await.unwrap();
#[turbo_tasks::function(operation, root)]
async fn operation() -> Result<Vc<()>> {
enable_stats();
for i in 0..10 {
let dvc = double(i);
double_vc(dvc).await.unwrap();
// use cached results
double_vc(dvc).await.unwrap();
}
for i in 0..5 {
let dvc = double(i);
double_vc(dvc).await.unwrap();
}
Ok(Vc::cell(()))
}
operation().read_strongly_consistent().await?;
assert_eq!(
stats_json(),
json!({
......@@ -97,19 +112,25 @@ async fn test_vc_receiving_task() -> Result<()> {
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_trait_methods() -> Result<()> {
run_without_cache_check(&REGISTRATION, async move {
unmark_top_level_task_may_leak_eventually_consistent_state();
enable_stats();
for i in 0..10 {
let wvc = wrap(i);
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();
}
// use cached results
for i in 0..5 {
let wvc = wrap(i);
wvc.double().await.unwrap();
wvc.double_vc().await.unwrap();
#[turbo_tasks::function(operation, root)]
async fn operation() -> Result<Vc<()>> {
enable_stats();
for i in 0..10 {
let wvc = wrap(i);
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();
}
// use cached results
for i in 0..5 {
let wvc = wrap(i);
wvc.double().await.unwrap();
wvc.double_vc().await.unwrap();
}
Ok(Vc::cell(()))
}
operation().read_strongly_consistent().await?;
assert_eq!(
stats_json(),
json!({
......@@ -135,27 +156,33 @@ async fn test_trait_methods() -> Result<()> {
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_dyn_trait_methods() -> Result<()> {
run_without_cache_check(&REGISTRATION, async move {
unmark_top_level_task_may_leak_eventually_consistent_state();
enable_stats();
for i in 0..10 {
let wvc: Vc<Box<dyn Doublable>> = Vc::upcast(wrap(i));
let _ =
tokio::try_join!(wvc.double().to_resolved(), wvc.double().to_resolved()).unwrap();
let _ = tokio::try_join!(wvc.double_vc().to_resolved(), wvc.double_vc().to_resolved())
.unwrap();
}
// use cached results
for i in 0..5 {
let wvc: Vc<Box<dyn Doublable>> = Vc::upcast(wrap(i));
let _ = wvc.double().to_resolved().await.unwrap();
let _ = wvc.double_vc().to_resolved().await.unwrap();
}
// use cached results without dynamic dispatch
for i in 0..2 {
let wvc = wrap(i);
let _ = wvc.double().await.unwrap();
let _ = wvc.double_vc().await.unwrap();
#[turbo_tasks::function(operation, root)]
async fn operation() -> Result<Vc<()>> {
enable_stats();
for i in 0..10 {
let wvc: Vc<Box<dyn Doublable>> = Vc::upcast(wrap(i));
let _ = tokio::try_join!(wvc.double().to_resolved(), wvc.double().to_resolved())
.unwrap();
let _ =
tokio::try_join!(wvc.double_vc().to_resolved(), wvc.double_vc().to_resolved())
.unwrap();
}
// use cached results
for i in 0..5 {
let wvc: Vc<Box<dyn Doublable>> = Vc::upcast(wrap(i));
let _ = wvc.double().to_resolved().await.unwrap();
let _ = wvc.double_vc().to_resolved().await.unwrap();
}
// use cached results without dynamic dispatch
for i in 0..2 {
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!(
stats_json(),
json!({
......@@ -182,13 +209,18 @@ async fn test_dyn_trait_methods() -> Result<()> {
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_no_execution() -> Result<()> {
run_without_cache_check(&REGISTRATION, async move {
unmark_top_level_task_may_leak_eventually_consistent_state();
enable_stats();
wrap_vc(double_vc(double(123)))
.double()
.double_vc()
.as_side_effect()
.await?;
#[turbo_tasks::function(operation, root)]
async fn operation() -> Result<Vc<()>> {
enable_stats();
wrap_vc(double_vc(double(123)))
.double()
.double_vc()
.as_side_effect()
.await?;
Ok(Vc::cell(()))
}
operation().read_strongly_consistent().await?;
assert_eq!(
stats_json(),
json!({
......@@ -222,9 +254,14 @@ async fn test_no_execution() -> Result<()> {
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_inline_definitions() -> Result<()> {
run_without_cache_check(&REGISTRATION, async move {
unmark_top_level_task_may_leak_eventually_consistent_state();
enable_stats();
inline_definitions().await?;
#[turbo_tasks::function(operation, root)]
async fn operation() -> Result<Vc<()>> {
enable_stats();
inline_definitions().await?;
Ok(Vc::cell(()))
}
operation().read_strongly_consistent().await?;
assert_eq!(
stats_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