react-code-dataset / next.js /turbopack /crates /turbo-tasks-backend /tests /transient_collectible.rs
| use serde::{Deserialize, Serialize}; | |
| use turbo_tasks::{NonLocalValue, ResolvedVc, TaskInput, trace::TraceRawVcs}; | |
| use turbo_tasks_testing::{Registration, register, run_without_cache_check}; | |
| static REGISTRATION: Registration = register!(); | |
| const EXPECTED_MSG: &str = | |
| "Collectible is transient, transient collectibles cannot be emitted from persistent tasks"; | |
| async fn test_transient_emit_from_persistent() { | |
| let result = run_without_cache_check(®ISTRATION, async { | |
| emit_incorrect_task_input_operation(IncorrectTaskInput(U32Wrapper(123).resolved_cell())) | |
| .read_strongly_consistent() | |
| .await?; | |
| anyhow::Ok(()) | |
| }) | |
| .await; | |
| let message = format!("{:#}", result.unwrap_err()); | |
| assert!(message.contains(&EXPECTED_MSG.to_string())); | |
| } | |
| fn emit_incorrect_task_input_operation(value: IncorrectTaskInput) { | |
| turbo_tasks::emit(ResolvedVc::upcast::<Box<dyn Number>>(value.0)); | |
| } | |
| /// Has an intentionally incorrect `TaskInput` implementation | |
| struct IncorrectTaskInput(ResolvedVc<U32Wrapper>); | |
| impl TaskInput for IncorrectTaskInput { | |
| fn is_transient(&self) -> bool { | |
| false | |
| } | |
| } | |
| trait Number {} | |
| struct U32Wrapper(u32); | |
| impl Number for U32Wrapper {} | |