Skip to content

Commit b7e9f18

Browse files
committed
pass test name to test_config to construct db name
1 parent 6034728 commit b7e9f18

File tree

5 files changed

+27
-17
lines changed

5 files changed

+27
-17
lines changed

turbopack/crates/turbo-tasks-backend/tests/test_config.trs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
|initial | {
2-
let path = std::path::PathBuf::from(concat!(
1+
|name, initial| {
2+
let path = std::path::PathBuf::from(format!(concat!(
33
env!("OUT_DIR"),
4-
"/.cache/",
5-
module_path!(),
6-
));
4+
"/.cache/{}",
5+
), name));
76
if initial {
87
let _ = std::fs::remove_dir_all(&path);
98
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
|_initial | {
1+
|_name, _initial | {
22
turbo_tasks::TurboTasks::new(turbo_tasks_memory::MemoryBackend::new(usize::MAX))
33
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
|_initial | {
1+
|_name, _initial | {
22
turbo_tasks::TurboTasks::new(turbo_tasks_memory::MemoryBackend::new(usize::MAX))
33
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
|_initial | {
1+
|_name, _initial | {
22
turbo_tasks::TurboTasks::new(turbo_tasks_memory::MemoryBackend::new(usize::MAX))
33
}

turbopack/crates/turbo-tasks-testing/src/run.rs

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,15 @@ use turbo_tasks::{run_once, trace::TraceRawVcs, TurboTasksApi};
1010
pub struct Registration {
1111
execution_lock: OnceLock<()>,
1212
func: fn(),
13-
create_turbo_tasks: fn(bool) -> Arc<dyn TurboTasksApi>,
13+
create_turbo_tasks: fn(&str, bool) -> Arc<dyn TurboTasksApi>,
1414
}
1515

1616
impl Registration {
1717
#[doc(hidden)]
18-
pub const fn new(create_turbo_tasks: fn(bool) -> Arc<dyn TurboTasksApi>, func: fn()) -> Self {
18+
pub const fn new(
19+
create_turbo_tasks: fn(&str, bool) -> Arc<dyn TurboTasksApi>,
20+
func: fn(),
21+
) -> Self {
1922
Registration {
2023
execution_lock: OnceLock::new(),
2124
func,
@@ -30,8 +33,8 @@ impl Registration {
3033
self.execution_lock.get_or_init(self.func);
3134
}
3235

33-
pub fn create_turbo_tasks(&self, initial: bool) -> Arc<dyn TurboTasksApi> {
34-
(self.create_turbo_tasks)(initial)
36+
pub fn create_turbo_tasks(&self, name: &str, initial: bool) -> Arc<dyn TurboTasksApi> {
37+
(self.create_turbo_tasks)(name, initial)
3538
}
3639
}
3740

@@ -40,12 +43,12 @@ macro_rules! register {
4043
($($other_register_fns:expr),* $(,)?) => {{
4144
use turbo_tasks::TurboTasksApi;
4245
use std::sync::Arc;
43-
fn create_turbo_tasks(initial: bool) -> Arc<dyn TurboTasksApi> {
46+
fn create_turbo_tasks(name: &str, initial: bool) -> Arc<dyn TurboTasksApi> {
4447
let inner = include!(concat!(
4548
env!("CARGO_MANIFEST_DIR"),
4649
"/tests/test_config.trs"
4750
));
48-
(inner)(initial)
51+
(inner)(name, initial)
4952
}
5053
fn register_impl() {
5154
$($other_register_fns();)*
@@ -69,10 +72,16 @@ where
6972
T: TraceRawVcs + Send + 'static,
7073
{
7174
registration.ensure_registered();
72-
let tt = registration.create_turbo_tasks(true);
75+
let name = closure_to_name(&fut);
76+
let tt = registration.create_turbo_tasks(&name, true);
7377
run_once(tt, async move { Ok(fut.await) }).await.unwrap()
7478
}
7579

80+
fn closure_to_name<T>(value: &T) -> String {
81+
let name = std::any::type_name_of_val(value);
82+
name.replace("::{{closure}}", "").replace("::", "_")
83+
}
84+
7685
pub async fn run<T, F>(
7786
registration: &Registration,
7887
fut: impl Fn() -> F + Send + 'static,
@@ -82,14 +91,16 @@ where
8291
T: Debug + PartialEq + Eq + TraceRawVcs + Send + 'static,
8392
{
8493
registration.ensure_registered();
85-
let tt = registration.create_turbo_tasks(true);
94+
95+
let name = closure_to_name(&fut);
96+
let tt = registration.create_turbo_tasks(&name, true);
8697
println!("Run #1 (without cache)");
8798
let first = run_once(tt.clone(), fut()).await?;
8899
println!("Run #2 (with memory cache, same TurboTasks instance)");
89100
let second = run_once(tt.clone(), fut()).await?;
90101
tt.stop_and_wait().await;
91102
assert_eq!(first, second);
92-
let tt = registration.create_turbo_tasks(false);
103+
let tt = registration.create_turbo_tasks(&name, false);
93104
println!("Run #3 (with persistent cache if available, new TurboTasks instance)");
94105
let third = run_once(tt.clone(), fut()).await?;
95106
tt.stop_and_wait().await;

0 commit comments

Comments
 (0)