From aaa5d6bc4fc547b6e3aaa1f21f99972e9c7ea1f0 Mon Sep 17 00:00:00 2001 From: Thomas Castiglione Date: Sat, 17 Feb 2024 10:42:58 +0800 Subject: [PATCH] working_copy: add Send supertrait If WorkingCopy: Send, then Workspace is Send, which is useful for long-running servers. All existing impls are Send already, so this is just a marker. --- lib/src/working_copy.rs | 2 +- lib/tests/test_workspace.rs | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/src/working_copy.rs b/lib/src/working_copy.rs index bb56b5016..0fbc8766a 100644 --- a/lib/src/working_copy.rs +++ b/lib/src/working_copy.rs @@ -32,7 +32,7 @@ use crate::settings::HumanByteSize; use crate::store::Store; /// The trait all working-copy implementations must implement. -pub trait WorkingCopy { +pub trait WorkingCopy: Send { /// Should return `self`. For down-casting purposes. fn as_any(&self) -> &dyn Any; diff --git a/lib/tests/test_workspace.rs b/lib/tests/test_workspace.rs index 7f97e3654..63c0e5250 100644 --- a/lib/tests/test_workspace.rs +++ b/lib/tests/test_workspace.rs @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +use std::thread; + use assert_matches::assert_matches; use jj_lib::op_store::WorkspaceId; use jj_lib::repo::Repo; @@ -84,3 +86,18 @@ fn test_init_additional_workspace() { ); assert_eq!(same_workspace.workspace_root(), ws2.workspace_root()); } + +/// Test cross-thread access to a workspace, which requires it to be Send +#[test] +fn test_sendable() { + let settings = testutils::user_settings(); + let test_workspace = TestWorkspace::init(&settings); + let root = test_workspace.workspace.workspace_root().clone(); + + thread::spawn(move || { + let shared_workspace = test_workspace.workspace; + assert_eq!(shared_workspace.workspace_root(), &root); + }) + .join() + .unwrap(); +}