In random collaboration test, compare all guests' buffers to the host's buffers
Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
parent
06fb9ccca0
commit
93ed34f918
2 changed files with 25 additions and 18 deletions
|
@ -344,6 +344,11 @@ impl Project {
|
||||||
cx.update(|cx| Project::local(client, user_store, languages, fs, cx))
|
cx.update(|cx| Project::local(client, user_store, languages, fs, cx))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(any(test, feature = "test-support"))]
|
||||||
|
pub fn shared_buffer(&self, peer_id: PeerId, remote_id: u64) -> Option<ModelHandle<Buffer>> {
|
||||||
|
Some(self.shared_buffers.get(&peer_id)?.get(&remote_id)?.clone())
|
||||||
|
}
|
||||||
|
|
||||||
pub fn fs(&self) -> &Arc<dyn Fs> {
|
pub fn fs(&self) -> &Arc<dyn Fs> {
|
||||||
&self.fs
|
&self.fs
|
||||||
}
|
}
|
||||||
|
|
|
@ -3711,13 +3711,13 @@ mod tests {
|
||||||
.collect::<BTreeMap<_, _>>()
|
.collect::<BTreeMap<_, _>>()
|
||||||
});
|
});
|
||||||
|
|
||||||
for (ix, (client_a, cx_a)) in clients.iter().enumerate() {
|
for (guest_ix, (guest_client, guest_cx)) in clients.iter().enumerate() {
|
||||||
let worktree_snapshots =
|
let worktree_snapshots =
|
||||||
client_a
|
guest_client
|
||||||
.project
|
.project
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.read_with(cx_a, |project, cx| {
|
.read_with(guest_cx, |project, cx| {
|
||||||
project
|
project
|
||||||
.worktrees(cx)
|
.worktrees(cx)
|
||||||
.map(|worktree| {
|
.map(|worktree| {
|
||||||
|
@ -3731,7 +3731,7 @@ mod tests {
|
||||||
worktree_snapshots.keys().collect::<Vec<_>>(),
|
worktree_snapshots.keys().collect::<Vec<_>>(),
|
||||||
host_worktree_snapshots.keys().collect::<Vec<_>>(),
|
host_worktree_snapshots.keys().collect::<Vec<_>>(),
|
||||||
"guest {} has different worktrees than the host",
|
"guest {} has different worktrees than the host",
|
||||||
ix
|
guest_ix
|
||||||
);
|
);
|
||||||
for (id, host_snapshot) in &host_worktree_snapshots {
|
for (id, host_snapshot) in &host_worktree_snapshots {
|
||||||
let guest_snapshot = &worktree_snapshots[id];
|
let guest_snapshot = &worktree_snapshots[id];
|
||||||
|
@ -3739,33 +3739,35 @@ mod tests {
|
||||||
guest_snapshot.root_name(),
|
guest_snapshot.root_name(),
|
||||||
host_snapshot.root_name(),
|
host_snapshot.root_name(),
|
||||||
"guest {} has different root name than the host for worktree {}",
|
"guest {} has different root name than the host for worktree {}",
|
||||||
ix,
|
guest_ix,
|
||||||
id
|
id
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
guest_snapshot.entries(false).collect::<Vec<_>>(),
|
guest_snapshot.entries(false).collect::<Vec<_>>(),
|
||||||
host_snapshot.entries(false).collect::<Vec<_>>(),
|
host_snapshot.entries(false).collect::<Vec<_>>(),
|
||||||
"guest {} has different snapshot than the host for worktree {}",
|
"guest {} has different snapshot than the host for worktree {}",
|
||||||
ix,
|
guest_ix,
|
||||||
id
|
id
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (client_b, cx_b) in &clients[ix + 1..] {
|
for guest_buffer in &guest_client.buffers {
|
||||||
for buffer_a in &client_a.buffers {
|
let buffer_id = guest_buffer.read_with(guest_cx, |buffer, _| buffer.remote_id());
|
||||||
let buffer_id = buffer_a.read_with(cx_a, |buffer, _| buffer.remote_id());
|
let host_buffer = host_project.read_with(&host_cx, |project, _| {
|
||||||
if let Some(buffer_b) = client_b.buffers.iter().find(|buffer| {
|
project
|
||||||
buffer.read_with(cx_b, |buffer, _| buffer.remote_id() == buffer_id)
|
.shared_buffer(guest_client.peer_id, buffer_id)
|
||||||
}) {
|
.unwrap()
|
||||||
|
});
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
buffer_a.read_with(cx_a, |buffer, _| buffer.text()),
|
guest_buffer.read_with(guest_cx, |buffer, _| buffer.text()),
|
||||||
buffer_b.read_with(cx_b, |buffer, _| buffer.text())
|
host_buffer.read_with(&host_cx, |buffer, _| buffer.text()),
|
||||||
|
"guest {} buffer {} differs from the host's buffer",
|
||||||
|
guest_ix,
|
||||||
|
buffer_id,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct TestServer {
|
struct TestServer {
|
||||||
peer: Arc<Peer>,
|
peer: Arc<Peer>,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue