Skip to content

Commit 5033dcb

Browse files
authored
Turbopack: run unit tests in multi threaded runtime (#82665)
### What? run unit tests in multi threaded runtime fix cache hit tracking
1 parent 116770b commit 5033dcb

31 files changed

+92
-114
lines changed

turbopack/crates/turbo-tasks-backend/src/backend/mod.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1267,7 +1267,6 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
12671267
return task_id;
12681268
}
12691269

1270-
self.track_cache_miss(&task_type);
12711270
let tx = self
12721271
.should_restore()
12731272
.then(|| self.backing_storage.start_read_transaction())
@@ -1279,6 +1278,7 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
12791278
.forward_lookup_task_cache(tx.as_ref(), &task_type)
12801279
.expect("Failed to lookup task id")
12811280
} {
1281+
self.track_cache_hit(&task_type);
12821282
let _ = self.task_cache.try_insert(Arc::new(task_type), task_id);
12831283
task_id
12841284
} else {
@@ -1287,12 +1287,14 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
12871287
let task_id = if let Err(existing_task_id) =
12881288
self.task_cache.try_insert(task_type.clone(), task_id)
12891289
{
1290+
self.track_cache_hit(&task_type);
12901291
// Safety: We just created the id and failed to insert it.
12911292
unsafe {
12921293
self.persisted_task_id_factory.reuse(task_id);
12931294
}
12941295
existing_task_id
12951296
} else {
1297+
self.track_cache_miss(&task_type);
12961298
task_id
12971299
};
12981300
if let Some(log) = &self.persisted_task_cache_log {
@@ -1327,10 +1329,10 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
13271329
return task_id;
13281330
}
13291331

1330-
self.track_cache_miss(&task_type);
13311332
let task_type = Arc::new(task_type);
13321333
let task_id = self.transient_task_id_factory.get();
1333-
if let Err(existing_task_id) = self.task_cache.try_insert(task_type, task_id) {
1334+
if let Err(existing_task_id) = self.task_cache.try_insert(task_type.clone(), task_id) {
1335+
self.track_cache_hit(&task_type);
13341336
// Safety: We just created the id and failed to insert it.
13351337
unsafe {
13361338
self.transient_task_id_factory.reuse(task_id);
@@ -1339,6 +1341,7 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
13391341
return existing_task_id;
13401342
}
13411343

1344+
self.track_cache_miss(&task_type);
13421345
self.connect_child(parent_task, task_id, turbo_tasks);
13431346

13441347
task_id

turbopack/crates/turbo-tasks-backend/tests/all_in_one.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use turbo_tasks_testing::{Registration, register, run};
99

1010
static REGISTRATION: Registration = register!();
1111

12-
#[tokio::test]
12+
#[tokio::test(flavor = "multi_thread")]
1313
async fn all_in_one() {
1414
run(&REGISTRATION, || async {
1515
let a: Vc<u32> = Vc::cell(4242);

turbopack/crates/turbo-tasks-backend/tests/basic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use turbo_tasks_testing::{Registration, register, run};
88

99
static REGISTRATION: Registration = register!();
1010

11-
#[tokio::test]
11+
#[tokio::test(flavor = "multi_thread")]
1212
async fn basic() {
1313
run(&REGISTRATION, || async {
1414
let output1 = func_without_args();

turbopack/crates/turbo-tasks-backend/tests/bug.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ struct TaskSpec {
2424
#[turbo_tasks::value(transparent)]
2525
struct TasksSpec(Vec<TaskSpec>);
2626

27-
#[tokio::test]
27+
#[tokio::test(flavor = "multi_thread")]
2828
async fn graph_bug() {
2929
// see https://github.com/vercel/next.js/pull/79451
3030
run(&REGISTRATION, || async {

turbopack/crates/turbo-tasks-backend/tests/bug2.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub struct TaskSpec {
3333
#[turbo_tasks::value(transparent)]
3434
struct Iteration(State<usize>);
3535

36-
#[tokio::test]
36+
#[tokio::test(flavor = "multi_thread")]
3737
async fn graph_bug() {
3838
run(&REGISTRATION, move || async move {
3939
let spec = vec![

turbopack/crates/turbo-tasks-backend/tests/call_types.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use turbo_tasks_testing::{Registration, register, run};
88

99
static REGISTRATION: Registration = register!();
1010

11-
#[tokio::test]
11+
#[tokio::test(flavor = "multi_thread")]
1212
async fn functions() {
1313
run(&REGISTRATION, || async {
1414
assert_eq!(*fn_plain().await?, 42);
@@ -53,7 +53,7 @@ async fn async_fn_vc_arg(n: Vc<u32>) -> Result<Vc<u32>> {
5353
Ok(Vc::cell(*n.await?))
5454
}
5555

56-
#[tokio::test]
56+
#[tokio::test(flavor = "multi_thread")]
5757
async fn methods() {
5858
run(&REGISTRATION, || async {
5959
assert_eq!(*Value::static_method().await?, 42);
@@ -106,7 +106,7 @@ impl Value {
106106
}
107107
}
108108

109-
#[tokio::test]
109+
#[tokio::test(flavor = "multi_thread")]
110110
async fn trait_methods() {
111111
run(&REGISTRATION, || async {
112112
assert_eq!(*Value::static_trait_method().await?, 42);

turbopack/crates/turbo-tasks-backend/tests/collectibles.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use turbo_tasks_testing::{Registration, register, run};
1414

1515
static REGISTRATION: Registration = register!();
1616

17-
#[tokio::test]
17+
#[tokio::test(flavor = "multi_thread")]
1818
async fn transitive_emitting() {
1919
run(&REGISTRATION, || async {
2020
let result_op = my_transitive_emitting_function(rcstr!(""), rcstr!(""));
@@ -32,7 +32,7 @@ async fn transitive_emitting() {
3232
.unwrap()
3333
}
3434

35-
#[tokio::test]
35+
#[tokio::test(flavor = "multi_thread")]
3636
async fn transitive_emitting_indirect() {
3737
run(&REGISTRATION, || async {
3838
let result_op = my_transitive_emitting_function(rcstr!(""), rcstr!(""));
@@ -50,7 +50,7 @@ async fn transitive_emitting_indirect() {
5050
.unwrap()
5151
}
5252

53-
#[tokio::test]
53+
#[tokio::test(flavor = "multi_thread")]
5454
async fn multi_emitting() {
5555
run(&REGISTRATION, || async {
5656
let result_op = my_multi_emitting_function();
@@ -68,7 +68,7 @@ async fn multi_emitting() {
6868
.unwrap()
6969
}
7070

71-
#[tokio::test]
71+
#[tokio::test(flavor = "multi_thread")]
7272
async fn taking_collectibles() {
7373
run(&REGISTRATION, || async {
7474
let result_op = my_collecting_function();
@@ -84,7 +84,7 @@ async fn taking_collectibles() {
8484
.unwrap()
8585
}
8686

87-
#[tokio::test]
87+
#[tokio::test(flavor = "multi_thread")]
8888
async fn taking_collectibles_extra_layer() {
8989
run(&REGISTRATION, || async {
9090
let result_op = my_collecting_function_indirect();
@@ -100,7 +100,7 @@ async fn taking_collectibles_extra_layer() {
100100
.unwrap()
101101
}
102102

103-
#[tokio::test]
103+
#[tokio::test(flavor = "multi_thread")]
104104
async fn taking_collectibles_parallel() {
105105
run(&REGISTRATION, || async {
106106
let result_op = my_transitive_emitting_function(rcstr!(""), rcstr!("a"));
@@ -142,7 +142,7 @@ async fn taking_collectibles_parallel() {
142142
.unwrap()
143143
}
144144

145-
#[tokio::test]
145+
#[tokio::test(flavor = "multi_thread")]
146146
async fn taking_collectibles_with_resolve() {
147147
run(&REGISTRATION, || async {
148148
let result_op = my_transitive_emitting_function_with_resolve(rcstr!("resolve"));

turbopack/crates/turbo-tasks-backend/tests/debug.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use turbo_tasks_testing::{Registration, register, run};
99

1010
static REGISTRATION: Registration = register!();
1111

12-
#[tokio::test]
12+
#[tokio::test(flavor = "multi_thread")]
1313
async fn primitive_debug() {
1414
run(&REGISTRATION, || async {
1515
let a: Vc<u32> = Vc::cell(42);
@@ -20,7 +20,7 @@ async fn primitive_debug() {
2020
.unwrap()
2121
}
2222

23-
#[tokio::test]
23+
#[tokio::test(flavor = "multi_thread")]
2424
async fn transparent_debug() {
2525
run(&REGISTRATION, || async {
2626
let a: Vc<Transparent> = Transparent(42).cell();
@@ -32,7 +32,7 @@ async fn transparent_debug() {
3232
.unwrap()
3333
}
3434

35-
#[tokio::test]
35+
#[tokio::test(flavor = "multi_thread")]
3636
async fn enum_none_debug() {
3737
run(&REGISTRATION, || async {
3838
let a: Vc<Enum> = Enum::None.cell();
@@ -44,7 +44,7 @@ async fn enum_none_debug() {
4444
.unwrap()
4545
}
4646

47-
#[tokio::test]
47+
#[tokio::test(flavor = "multi_thread")]
4848
async fn enum_transparent_debug() {
4949
run(&REGISTRATION, || async {
5050
let a: Vc<Enum> = Enum::Transparent(Transparent(42).resolved_cell()).cell();
@@ -60,7 +60,7 @@ async fn enum_transparent_debug() {
6060
.unwrap()
6161
}
6262

63-
#[tokio::test]
63+
#[tokio::test(flavor = "multi_thread")]
6464
async fn enum_inner_vc_debug() {
6565
run(&REGISTRATION, || async {
6666
let a: Vc<Enum> = Enum::Enum(Enum::None.resolved_cell()).cell();
@@ -76,7 +76,7 @@ async fn enum_inner_vc_debug() {
7676
.unwrap()
7777
}
7878

79-
#[tokio::test]
79+
#[tokio::test(flavor = "multi_thread")]
8080
async fn struct_unit_debug() {
8181
run(&REGISTRATION, || async {
8282
let a: Vc<StructUnit> = StructUnit.cell();
@@ -87,7 +87,7 @@ async fn struct_unit_debug() {
8787
.unwrap()
8888
}
8989

90-
#[tokio::test]
90+
#[tokio::test(flavor = "multi_thread")]
9191
async fn struct_transparent_debug() {
9292
run(&REGISTRATION, || async {
9393
let a: Vc<StructWithTransparent> = StructWithTransparent {
@@ -106,7 +106,7 @@ async fn struct_transparent_debug() {
106106
.unwrap()
107107
}
108108

109-
#[tokio::test]
109+
#[tokio::test(flavor = "multi_thread")]
110110
async fn struct_vec_debug() {
111111
run(&REGISTRATION, || async {
112112
let a: Vc<StructWithVec> = StructWithVec { vec: vec![] }.cell();
@@ -135,7 +135,7 @@ async fn struct_vec_debug() {
135135
.unwrap()
136136
}
137137

138-
#[tokio::test]
138+
#[tokio::test(flavor = "multi_thread")]
139139
async fn struct_ignore_debug() {
140140
run(&REGISTRATION, || async {
141141
let a: Vc<StructWithIgnore> = StructWithIgnore {

turbopack/crates/turbo-tasks-backend/tests/detached.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use turbo_tasks_testing::{Registration, register, run};
1515

1616
static REGISTRATION: Registration = register!();
1717

18-
#[tokio::test]
18+
#[tokio::test(flavor = "multi_thread")]
1919
async fn test_spawns_detached() -> anyhow::Result<()> {
2020
run(&REGISTRATION, || async {
2121
// HACK: The watch channel we use has an incorrect implementation of `TraceRawVcs`, just
@@ -82,7 +82,7 @@ async fn spawns_detached(
8282
Vc::cell(())
8383
}
8484

85-
#[tokio::test]
85+
#[tokio::test(flavor = "multi_thread")]
8686
async fn test_spawns_detached_changing() -> anyhow::Result<()> {
8787
run(&REGISTRATION, || async {
8888
// HACK: The watch channel we use has an incorrect implementation of `TraceRawVcs`

turbopack/crates/turbo-tasks-backend/tests/dirty_in_progress.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use turbo_tasks_testing::{Registration, register, run};
1111

1212
static REGISTRATION: Registration = register!();
1313

14-
#[tokio::test]
14+
#[tokio::test(flavor = "multi_thread")]
1515
async fn dirty_in_progress() {
1616
run(&REGISTRATION, || async {
1717
let cases = [

0 commit comments

Comments
 (0)