From abfebfea8734a1d452c9c8c69fea2bdd48c8e8da Mon Sep 17 00:00:00 2001 From: Kayshen-X Date: Wed, 29 Jul 2026 22:39:21 +0800 Subject: [PATCH] test(collab): wait for retired worker slot --- .../src/collab_runtime/network/lifecycle.rs | 14 ++++++++++++++ crates/op-host-desktop/src/collab_runtime/tests.rs | 2 ++ 2 files changed, 16 insertions(+) diff --git a/crates/op-host-desktop/src/collab_runtime/network/lifecycle.rs b/crates/op-host-desktop/src/collab_runtime/network/lifecycle.rs index 3bf8efd53..39ab49e09 100644 --- a/crates/op-host-desktop/src/collab_runtime/network/lifecycle.rs +++ b/crates/op-host-desktop/src/collab_runtime/network/lifecycle.rs @@ -114,6 +114,20 @@ impl DesktopCollabRuntime { } } + #[cfg(test)] + pub(in crate::collab_runtime) fn wait_for_worker_slot_for_test(&mut self) { + // Tests that inject a replacement transport must cross the same + // retirement acknowledgement gate as launch_pending_network. + let deadline = std::time::Instant::now() + std::time::Duration::from_secs(2); + while self.require_worker_slot().is_err() { + assert!( + std::time::Instant::now() < deadline, + "retired collaboration worker must release its slot" + ); + std::thread::yield_now(); + } + } + pub(in crate::collab_runtime) fn retire_workers(&mut self) { // A generation identifies one worker incarnation, not the retained // guest session actor. Fence it before requesting shutdown so neither diff --git a/crates/op-host-desktop/src/collab_runtime/tests.rs b/crates/op-host-desktop/src/collab_runtime/tests.rs index d5cb75e54..10f72ed25 100644 --- a/crates/op-host-desktop/src/collab_runtime/tests.rs +++ b/crates/op-host-desktop/src/collab_runtime/tests.rs @@ -615,6 +615,8 @@ fn retry_against_new_epoch_ends_without_replaying_pending_edit() { }, &mut host, ); + runtime.wait_for_worker_slot_for_test(); + assert!(runtime.network.is_none()); let (network, retry_commands) = guest_command_channel_with_capacity_for_test(8); runtime.network = Some(network); let retry_connection = connection(3);