diff --git a/crates/gpui/src/executor.rs b/crates/gpui/src/executor.rs index 5dc88feb48994b6040c3d2ad725588d501afa7b8..5d6c8641e03a1bdc217e8024fbd1daa3098f3428 100644 --- a/crates/gpui/src/executor.rs +++ b/crates/gpui/src/executor.rs @@ -1220,4 +1220,26 @@ mod test { let result = background_executor.block(task); assert_eq!(result, None, "Cancelled task should return None"); } + + #[test] + fn test_app_liveness_token_can_be_dropped_on_background_thread() { + let dispatcher = TestDispatcher::new(StdRng::seed_from_u64(0)); + let arc_dispatcher = Arc::new(dispatcher.clone()); + let background_executor = BackgroundExecutor::new(arc_dispatcher.clone()); + let foreground_executor = ForegroundExecutor::new(arc_dispatcher); + + let platform = TestPlatform::new(background_executor, foreground_executor); + let asset_source = Arc::new(()); + let http_client = http_client::FakeHttpClient::with_404_response(); + + let app = App::new_app(platform, asset_source, http_client); + let liveness_token = app.borrow().liveness.token(); + + // Drop the token on a real background thread. + std::thread::spawn(move || { + drop(liveness_token); + }) + .join() + .expect("Dropping AppLivenessToken on background thread should not panic"); + } }