Skip to content

Commit

Permalink
allow to change backend on turbo tasks tests
Browse files Browse the repository at this point in the history
add tests for new backend
  • Loading branch information
sokra committed Aug 5, 2024
1 parent 27aa7e8 commit d55f440
Show file tree
Hide file tree
Showing 36 changed files with 71 additions and 15 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions turbopack/crates/turbo-tasks-backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,22 @@ anyhow = { workspace = true }
async-trait = { workspace = true }
auto-hash-map = { workspace = true }
dashmap = { workspace = true }
indexmap = { workspace = true }
once_cell = { workspace = true }
parking_lot = { workspace = true }
rand = { workspace = true }
regex = { workspace = true }
rustc-hash = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
smallvec = { workspace = true }
tokio = { workspace = true }
tracing = { workspace = true }
turbo-prehash = { workspace = true }
turbo-tasks = { workspace = true }
turbo-tasks-hash = { workspace = true }
turbo-tasks-malloc = { workspace = true, default-features = false }
turbo-tasks-testing = { workspace = true }

[build-dependencies]
turbo-tasks-build = { workspace = true }
1 change: 1 addition & 0 deletions turbopack/crates/turbo-tasks-backend/tests/all_in_one.rs
1 change: 1 addition & 0 deletions turbopack/crates/turbo-tasks-backend/tests/call_types.rs
1 change: 1 addition & 0 deletions turbopack/crates/turbo-tasks-backend/tests/collectibles.rs
1 change: 1 addition & 0 deletions turbopack/crates/turbo-tasks-backend/tests/debug.rs
1 change: 1 addition & 0 deletions turbopack/crates/turbo-tasks-backend/tests/generics.rs
1 change: 1 addition & 0 deletions turbopack/crates/turbo-tasks-backend/tests/recompute.rs
1 change: 1 addition & 0 deletions turbopack/crates/turbo-tasks-backend/tests/scope_stress.rs
1 change: 1 addition & 0 deletions turbopack/crates/turbo-tasks-backend/tests/test_config.trs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
turbo_tasks::TurboTasks::new(turbo_tasks_backend::TurboTasksBackend::new())
1 change: 1 addition & 0 deletions turbopack/crates/turbo-tasks-fetch/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ turbopack-core = { workspace = true }
httpmock = { workspace = true }
tokio = { workspace = true, features = ["full"] }
turbo-tasks-testing = { workspace = true }
turbo-tasks-memory = { workspace = true }

[build-dependencies]
turbo-tasks-build = { workspace = true }
1 change: 1 addition & 0 deletions turbopack/crates/turbo-tasks-fetch/tests/test_config.trs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
turbo_tasks::TurboTasks::new(turbo_tasks_memory::MemoryBackend::new(usize::MAX))
1 change: 1 addition & 0 deletions turbopack/crates/turbo-tasks-macros-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ tokio = { workspace = true }
trybuild = { version = "1.0.97" }
turbo-tasks = { workspace = true }
turbo-tasks-testing = { workspace = true }
turbo-tasks-memory = { workspace = true }

[build-dependencies]
turbo-tasks-build = { workspace = true }
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
turbo_tasks::TurboTasks::new(turbo_tasks_memory::MemoryBackend::new(usize::MAX))
1 change: 0 additions & 1 deletion turbopack/crates/turbo-tasks-memory/tests

This file was deleted.

1 change: 1 addition & 0 deletions turbopack/crates/turbo-tasks-memory/tests/all_in_one.rs
1 change: 1 addition & 0 deletions turbopack/crates/turbo-tasks-memory/tests/call_types.rs
1 change: 1 addition & 0 deletions turbopack/crates/turbo-tasks-memory/tests/collectibles.rs
1 change: 1 addition & 0 deletions turbopack/crates/turbo-tasks-memory/tests/debug.rs
1 change: 1 addition & 0 deletions turbopack/crates/turbo-tasks-memory/tests/emptied_cells.rs
1 change: 1 addition & 0 deletions turbopack/crates/turbo-tasks-memory/tests/generics.rs
1 change: 1 addition & 0 deletions turbopack/crates/turbo-tasks-memory/tests/read_ref_cell.rs
1 change: 1 addition & 0 deletions turbopack/crates/turbo-tasks-memory/tests/recompute.rs
1 change: 1 addition & 0 deletions turbopack/crates/turbo-tasks-memory/tests/scope_stress.rs
1 change: 1 addition & 0 deletions turbopack/crates/turbo-tasks-memory/tests/test_config.trs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
turbo_tasks::TurboTasks::new(turbo_tasks_memory::MemoryBackend::new(usize::MAX))
30 changes: 23 additions & 7 deletions turbopack/crates/turbo-tasks-testing/src/run.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
use std::{future::Future, sync::OnceLock};
use std::{
future::Future,
sync::{Arc, OnceLock},
};

use turbo_tasks::{trace::TraceRawVcs, TurboTasks};
use turbo_tasks_memory::MemoryBackend;
use turbo_tasks::{run_once, trace::TraceRawVcs, TurboTasksApi};

pub struct Registration {
execution_lock: OnceLock<()>,
func: fn(),
create_turbo_tasks: fn() -> Arc<dyn TurboTasksApi>,
}

impl Registration {
#[doc(hidden)]
pub const fn new(func: fn()) -> Self {
pub const fn new(create_turbo_tasks: fn() -> Arc<dyn TurboTasksApi>, func: fn()) -> Self {
Registration {
execution_lock: OnceLock::new(),
func,
create_turbo_tasks,
}
}

Expand All @@ -23,11 +27,23 @@ impl Registration {
pub fn ensure_registered(&self) {
self.execution_lock.get_or_init(self.func);
}

pub fn create_turbo_tasks(&self) -> Arc<dyn TurboTasksApi> {
(self.create_turbo_tasks)()
}
}

#[macro_export]
macro_rules! register {
($($other_register_fns:expr),* $(,)?) => {{
use turbo_tasks::TurboTasksApi;
use std::sync::Arc;
fn create_turbo_tasks() -> Arc<dyn TurboTasksApi> {
include!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/tests/test_config.trs"
))
}
fn register_impl() {
$($other_register_fns();)*
turbo_tasks::register();
Expand All @@ -38,7 +54,7 @@ macro_rules! register {
".rs",
));
}
turbo_tasks_testing::Registration::new(register_impl)
turbo_tasks_testing::Registration::new(create_turbo_tasks, register_impl)
}};
}

Expand All @@ -47,6 +63,6 @@ where
T: TraceRawVcs + Send + 'static,
{
registration.ensure_registered();
let tt = TurboTasks::new(MemoryBackend::default());
tt.run_once(async move { Ok(fut.await) }).await.unwrap()
let tt = registration.create_turbo_tasks();
run_once(tt, async move { Ok(fut.await) }).await.unwrap()
}
13 changes: 6 additions & 7 deletions turbopack/crates/turbo-tasks-testing/tests/scope_stress.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#![feature(arbitrary_self_types)]

use anyhow::Result;
use turbo_tasks::{Completion, TryJoinIterExt, TurboTasks, Vc};
use turbo_tasks_memory::MemoryBackend;
use turbo_tasks::{run_once, Completion, TryJoinIterExt, Vc};
use turbo_tasks_testing::{register, Registration};

static REGISTRATION: Registration = register!();
Expand All @@ -15,21 +14,21 @@ fn rectangle_stress() {
.build()
.unwrap();
rt.block_on(async {
let tt = TurboTasks::new(MemoryBackend::default());
let tt = REGISTRATION.create_turbo_tasks();
let size = std::env::var("TURBOPACK_TEST_RECTANGLE_STRESS_SIZE")
.map(|size| size.parse().unwrap())
.unwrap_or(50);
(0..size)
.map(|a| (a, size - 1))
.chain((0..size - 1).map(|b| (size - 1, b)))
.map(|(a, b)| {
let tt = &tt;
let tt = tt.clone();
async move {
let task = tt.spawn_once_task(async move {
run_once(tt, async move {
rectangle(a, b).strongly_consistent().await?;
Ok(Vc::<()>::default())
});
tt.wait_task_completion(task, false).await
})
.await
}
})
.try_join()
Expand Down

0 comments on commit d55f440

Please sign in to comment.