Unverified Commit 9487264f authored by Luke Sandberg's avatar Luke Sandberg Committed by GitHub

test(turbopack): add strong read operation roots (#98248)

## Summary

Replace top-level consistency suppression in read-ref and trait-ref cell
tests with explicit operation roots. The operations separately cover
counter creation, counter reads, and trait upcasts while preserving the
tests’ warm-cache and snapshot behavior.

## Verification

- `cargo test -p turbo-tasks-backend --test read_ref_cell --test
trait_ref_cell`
- `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 357b2b3c
......@@ -5,10 +5,7 @@
use std::{collections::HashSet, mem::take, sync::Mutex};
use anyhow::Result;
use turbo_tasks::{
Invalidator, ReadRef, Vc, get_invalidator,
unmark_top_level_task_may_leak_eventually_consistent_state, with_turbo_tasks,
};
use turbo_tasks::{Invalidator, ReadRef, Vc, get_invalidator, with_turbo_tasks};
use turbo_tasks_testing::{Registration, register, run_once};
static REGISTRATION: Registration = register!();
......@@ -16,7 +13,6 @@ static REGISTRATION: Registration = register!();
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_read_ref() {
run_once(&REGISTRATION, async || {
unmark_top_level_task_may_leak_eventually_consistent_state();
let counter = Counter::cell(Counter {
value: Mutex::new((0, Default::default())),
});
......@@ -38,7 +34,8 @@ async fn test_read_ref() {
// However, `local_counter_value` will point to the value of `counter_value`
// at the time it was turned into a trait reference (just like a `ReadRef`
// would).
let local_counter_value = ReadRef::cell(counter_value.await?).get_value();
let local_counter_value =
ReadRef::cell(counter_value.strongly_consistent().await?).get_value();
counter.await?.incr();
......
......@@ -5,10 +5,7 @@
use std::{collections::HashSet, mem::take, sync::Mutex};
use anyhow::Result;
use turbo_tasks::{
Invalidator, TraitRef, Vc, get_invalidator,
unmark_top_level_task_may_leak_eventually_consistent_state, with_turbo_tasks,
};
use turbo_tasks::{Invalidator, ResolvedVc, TraitRef, Vc, get_invalidator, with_turbo_tasks};
use turbo_tasks_testing::{Registration, register, run_once};
static REGISTRATION: Registration = register!();
......@@ -16,8 +13,19 @@ static REGISTRATION: Registration = register!();
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn trait_ref() {
run_once(&REGISTRATION, async || {
unmark_top_level_task_may_leak_eventually_consistent_state();
let counter = Counter::cell(Counter {
#[turbo_tasks::function(operation, root)]
fn counter_trait_operation(counter: ResolvedVc<Counter>) -> Vc<Box<dyn CounterTrait>> {
Vc::upcast(*counter)
}
#[turbo_tasks::function(operation, root)]
fn counter_value_trait_operation(
counter: ResolvedVc<Counter>,
) -> Vc<Box<dyn CounterValueTrait>> {
Vc::upcast(counter.get_value())
}
let counter = Counter::resolved_cell(Counter {
value: Mutex::new((0, Default::default())),
});
......@@ -32,8 +40,8 @@ async fn trait_ref() {
assert_eq!(*counter_value.strongly_consistent().await?, 1);
// `ref_counter` will still point to the same `counter` instance as `counter`.
let trait_ref_counter = Vc::upcast::<Box<dyn CounterTrait>>(counter)
.into_trait_ref()
let trait_ref_counter = counter_trait_operation(counter)
.read_trait_strongly_consistent()
.await?;
let ref_counter = TraitRef::cell(trait_ref_counter.clone());
let ref_counter_value = ref_counter.get_value();
......@@ -42,8 +50,8 @@ async fn trait_ref() {
// at the time it was turned into a trait reference (just like a `ReadRef`
// would).
let local_counter_value = TraitRef::cell(
Vc::upcast::<Box<dyn CounterValueTrait>>(counter_value)
.into_trait_ref()
counter_value_trait_operation(counter)
.read_trait_strongly_consistent()
.await?,
)
.get_value();
......
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