Fix randomized test failure caused by unsharing while guest was joining
Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
parent
dd684d26a1
commit
5789aeea24
5 changed files with 73 additions and 63 deletions
|
@ -336,31 +336,46 @@ impl Server {
|
|||
}
|
||||
|
||||
async fn sign_out(self: &mut Arc<Self>, connection_id: ConnectionId) -> Result<()> {
|
||||
println!("Signing out {:?}", connection_id);
|
||||
self.peer.disconnect(connection_id);
|
||||
let removed_connection = self.store_mut().await.remove_connection(connection_id)?;
|
||||
|
||||
for (project_id, project) in removed_connection.hosted_projects {
|
||||
broadcast(connection_id, project.guests.keys().copied(), |conn_id| {
|
||||
self.peer
|
||||
.send(conn_id, proto::UnregisterProject { project_id })
|
||||
});
|
||||
}
|
||||
let removed_user_id = {
|
||||
let mut store = self.store_mut().await;
|
||||
let removed_connection = store.remove_connection(connection_id)?;
|
||||
|
||||
for (project_id, peer_ids) in removed_connection.guest_project_ids {
|
||||
broadcast(connection_id, peer_ids, |conn_id| {
|
||||
self.peer.send(
|
||||
conn_id,
|
||||
proto::RemoveProjectCollaborator {
|
||||
project_id,
|
||||
peer_id: connection_id.0,
|
||||
},
|
||||
)
|
||||
});
|
||||
}
|
||||
for (project_id, project) in removed_connection.hosted_projects {
|
||||
broadcast(connection_id, project.guests.keys().copied(), |conn_id| {
|
||||
self.peer
|
||||
.send(conn_id, proto::UnregisterProject { project_id })
|
||||
});
|
||||
}
|
||||
|
||||
self.update_user_contacts(removed_connection.user_id)
|
||||
.await?;
|
||||
for project_id in removed_connection.guest_project_ids {
|
||||
if let Some(project) = store.project(project_id).trace_err() {
|
||||
if project.guests.is_empty() {
|
||||
self.peer
|
||||
.send(
|
||||
project.host_connection_id,
|
||||
proto::ProjectUnshared { project_id },
|
||||
)
|
||||
.trace_err();
|
||||
} else {
|
||||
broadcast(connection_id, project.connection_ids(), |conn_id| {
|
||||
self.peer.send(
|
||||
conn_id,
|
||||
proto::RemoveProjectCollaborator {
|
||||
project_id,
|
||||
peer_id: connection_id.0,
|
||||
},
|
||||
)
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
removed_connection.user_id
|
||||
};
|
||||
|
||||
self.update_user_contacts(removed_user_id).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -829,7 +844,6 @@ impl Server {
|
|||
request: TypedEnvelope<proto::UpdateBuffer>,
|
||||
response: Response<proto::UpdateBuffer>,
|
||||
) -> Result<()> {
|
||||
println!("{:?}: update buffer", request.sender_id);
|
||||
let receiver_ids = self
|
||||
.store()
|
||||
.await
|
||||
|
|
|
@ -51,7 +51,7 @@ pub type ReplicaId = u16;
|
|||
pub struct RemovedConnectionState {
|
||||
pub user_id: UserId,
|
||||
pub hosted_projects: HashMap<u64, Project>,
|
||||
pub guest_project_ids: HashMap<u64, Vec<ConnectionId>>,
|
||||
pub guest_project_ids: HashSet<u64>,
|
||||
pub contact_ids: HashSet<UserId>,
|
||||
}
|
||||
|
||||
|
@ -134,10 +134,8 @@ impl Store {
|
|||
for project_id in connection.projects.clone() {
|
||||
if let Ok(project) = self.unregister_project(project_id, connection_id) {
|
||||
result.hosted_projects.insert(project_id, project);
|
||||
} else if let Ok(project) = self.leave_project(connection_id, project_id) {
|
||||
result
|
||||
.guest_project_ids
|
||||
.insert(project_id, project.connection_ids);
|
||||
} else if self.leave_project(connection_id, project_id).is_ok() {
|
||||
result.guest_project_ids.insert(project_id);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue