Skip to content

Commit

Permalink
Re-add local_cell tests, disable newly failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bgw committed Aug 14, 2024
1 parent 02ecb50 commit ca54835
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 14 deletions.
1 change: 1 addition & 0 deletions turbopack/crates/turbo-tasks-memory/tests/local_cell.rs
46 changes: 32 additions & 14 deletions turbopack/crates/turbo-tasks-testing/tests/local_cell.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![feature(arbitrary_self_types)]

use anyhow::Result;
use turbo_tasks::{
debug::ValueDebug, test_helpers::current_task_for_testing, ResolvedValue, ValueDefault, Vc,
};
Expand All @@ -14,8 +15,8 @@ struct Wrapper(u32);
struct TransparentWrapper(u32);

#[tokio::test]
async fn test_store_and_read() {
run(&REGISTRATION, async {
async fn test_store_and_read() -> Result<()> {
run(&REGISTRATION, || async {
let a: Vc<u32> = Vc::local_cell(42);
assert_eq!(*a.await.unwrap(), 42);

Expand All @@ -24,13 +25,15 @@ async fn test_store_and_read() {

let c = TransparentWrapper(42).local_cell();
assert_eq!(*c.await.unwrap(), 42);

Ok(())
})
.await
}

#[tokio::test]
async fn test_store_and_read_generic() {
run(&REGISTRATION, async {
async fn test_store_and_read_generic() -> Result<()> {
run(&REGISTRATION, || async {
// `Vc<Vec<Vc<T>>>` is stored as `Vc<Vec<Vc<()>>>` and requires special
// transmute handling
let cells: Vc<Vec<Vc<u32>>> =
Expand All @@ -42,6 +45,8 @@ async fn test_store_and_read_generic() {
}

assert_eq!(output, vec![1, 2, 3]);

Ok(())
})
.await
}
Expand All @@ -53,10 +58,12 @@ async fn returns_resolved_local_vc() -> Vc<u32> {
cell.resolve().await.unwrap()
}

#[ignore]
#[tokio::test]
async fn test_return_resolved() {
run(&REGISTRATION, async {
async fn test_return_resolved() -> Result<()> {
run(&REGISTRATION, || async {
assert_eq!(*returns_resolved_local_vc().await.unwrap(), 42);
Ok(())
})
.await
}
Expand All @@ -65,8 +72,8 @@ async fn test_return_resolved() {
trait UnimplementedTrait {}

#[tokio::test]
async fn test_try_resolve_sidecast() {
run(&REGISTRATION, async {
async fn test_try_resolve_sidecast() -> Result<()> {
run(&REGISTRATION, || async {
let trait_vc: Vc<Box<dyn ValueDebug>> = Vc::upcast(Vc::<u32>::local_cell(42));

// `u32` is both a `ValueDebug` and a `ValueDefault`, so this sidecast is valid
Expand All @@ -80,13 +87,15 @@ async fn test_try_resolve_sidecast() {
.await
.unwrap();
assert!(wrongly_sidecast_vc.is_none());

Ok(())
})
.await
}

#[tokio::test]
async fn test_try_resolve_downcast_type() {
run(&REGISTRATION, async {
async fn test_try_resolve_downcast_type() -> Result<()> {
run(&REGISTRATION, || async {
let trait_vc: Vc<Box<dyn ValueDebug>> = Vc::upcast(Vc::<u32>::local_cell(42));

let downcast_vc: Vc<u32> = Vc::try_resolve_downcast_type(trait_vc)
Expand All @@ -98,16 +107,19 @@ async fn test_try_resolve_downcast_type() {
let wrongly_downcast_vc: Option<Vc<i64>> =
Vc::try_resolve_downcast_type(trait_vc).await.unwrap();
assert!(wrongly_downcast_vc.is_none());

Ok(())
})
.await
}

#[tokio::test]
async fn test_get_task_id() {
run(&REGISTRATION, async {
async fn test_get_task_id() -> Result<()> {
run(&REGISTRATION, || async {
// the task id as reported by the RawVc
let vc_task_id = Vc::into_raw(Vc::<()>::local_cell(())).get_task_id();
assert_eq!(vc_task_id, current_task_for_testing());
Ok(())
})
.await
}
Expand Down Expand Up @@ -139,25 +151,31 @@ async fn get_untracked_local_cell() -> Vc<Untracked> {
.unwrap()
}

#[ignore]
#[tokio::test]
#[should_panic(expected = "Local Vcs must only be accessed within their own task")]
async fn test_panics_on_local_cell_escape_read() {
run(&REGISTRATION, async {
run(&REGISTRATION, || async {
get_untracked_local_cell()
.await
.unwrap()
.cell
.await
.unwrap();
Ok(())
})
.await
.unwrap()
}

#[ignore]
#[tokio::test]
#[should_panic(expected = "Local Vcs must only be accessed within their own task")]
async fn test_panics_on_local_cell_escape_get_task_id() {
run(&REGISTRATION, async {
run(&REGISTRATION, || async {
Vc::into_raw(get_untracked_local_cell().await.unwrap().cell).get_task_id();
Ok(())
})
.await
.unwrap()
}

0 comments on commit ca54835

Please sign in to comment.