mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-24 02:46:43 +00:00
Add failing test for switching leaders in a pane
This commit is contained in:
parent
29ccdb3cd9
commit
af90077a6a
1 changed files with 70 additions and 86 deletions
|
@ -184,20 +184,12 @@ async fn test_basic_following(
|
||||||
|
|
||||||
// All clients see that clients B and C are following client A.
|
// All clients see that clients B and C are following client A.
|
||||||
cx_c.foreground().run_until_parked();
|
cx_c.foreground().run_until_parked();
|
||||||
for (name, active_call, cx) in [
|
for (name, cx) in [("A", &cx_a), ("B", &cx_b), ("C", &cx_c), ("D", &cx_d)] {
|
||||||
("A", &active_call_a, &cx_a),
|
assert_eq!(
|
||||||
("B", &active_call_b, &cx_b),
|
followers_by_leader(project_id, cx),
|
||||||
("C", &active_call_c, &cx_c),
|
&[(peer_id_a, vec![peer_id_b, peer_id_c])],
|
||||||
("D", &active_call_d, &cx_d),
|
"followers seen by {name}"
|
||||||
] {
|
);
|
||||||
active_call.read_with(*cx, |call, cx| {
|
|
||||||
let room = call.room().unwrap().read(cx);
|
|
||||||
assert_eq!(
|
|
||||||
room.followers_for(peer_id_a, project_id),
|
|
||||||
&[peer_id_b, peer_id_c],
|
|
||||||
"checking followers for A as {name}"
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Client C unfollows client A.
|
// Client C unfollows client A.
|
||||||
|
@ -207,46 +199,39 @@ async fn test_basic_following(
|
||||||
|
|
||||||
// All clients see that clients B is following client A.
|
// All clients see that clients B is following client A.
|
||||||
cx_c.foreground().run_until_parked();
|
cx_c.foreground().run_until_parked();
|
||||||
for (name, active_call, cx) in [
|
for (name, cx) in [("A", &cx_a), ("B", &cx_b), ("C", &cx_c), ("D", &cx_d)] {
|
||||||
("A", &active_call_a, &cx_a),
|
assert_eq!(
|
||||||
("B", &active_call_b, &cx_b),
|
followers_by_leader(project_id, cx),
|
||||||
("C", &active_call_c, &cx_c),
|
&[(peer_id_a, vec![peer_id_b])],
|
||||||
("D", &active_call_d, &cx_d),
|
"followers seen by {name}"
|
||||||
] {
|
);
|
||||||
active_call.read_with(*cx, |call, cx| {
|
|
||||||
let room = call.room().unwrap().read(cx);
|
|
||||||
assert_eq!(
|
|
||||||
room.followers_for(peer_id_a, project_id),
|
|
||||||
&[peer_id_b],
|
|
||||||
"checking followers for A as {name}"
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Client C re-follows client A.
|
// Client C re-follows client A.
|
||||||
workspace_c.update(cx_c, |workspace, cx| {
|
workspace_c
|
||||||
workspace.follow(peer_id_a, cx);
|
.update(cx_c, |workspace, cx| {
|
||||||
});
|
workspace.follow(peer_id_a, cx).unwrap()
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
// All clients see that clients B and C are following client A.
|
// All clients see that clients B and C are following client A.
|
||||||
cx_c.foreground().run_until_parked();
|
cx_c.foreground().run_until_parked();
|
||||||
for (name, active_call, cx) in [
|
for (name, cx) in [("A", &cx_a), ("B", &cx_b), ("C", &cx_c), ("D", &cx_d)] {
|
||||||
("A", &active_call_a, &cx_a),
|
assert_eq!(
|
||||||
("B", &active_call_b, &cx_b),
|
followers_by_leader(project_id, cx),
|
||||||
("C", &active_call_c, &cx_c),
|
&[(peer_id_a, vec![peer_id_b, peer_id_c])],
|
||||||
("D", &active_call_d, &cx_d),
|
"followers seen by {name}"
|
||||||
] {
|
);
|
||||||
active_call.read_with(*cx, |call, cx| {
|
|
||||||
let room = call.room().unwrap().read(cx);
|
|
||||||
assert_eq!(
|
|
||||||
room.followers_for(peer_id_a, project_id),
|
|
||||||
&[peer_id_b, peer_id_c],
|
|
||||||
"checking followers for A as {name}"
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Client D follows client C.
|
// Client D follows client B, then switches to following client C.
|
||||||
|
workspace_d
|
||||||
|
.update(cx_d, |workspace, cx| {
|
||||||
|
workspace.follow(peer_id_b, cx).unwrap()
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
workspace_d
|
workspace_d
|
||||||
.update(cx_d, |workspace, cx| {
|
.update(cx_d, |workspace, cx| {
|
||||||
workspace.follow(peer_id_c, cx).unwrap()
|
workspace.follow(peer_id_c, cx).unwrap()
|
||||||
|
@ -256,20 +241,15 @@ async fn test_basic_following(
|
||||||
|
|
||||||
// All clients see that D is following C
|
// All clients see that D is following C
|
||||||
cx_d.foreground().run_until_parked();
|
cx_d.foreground().run_until_parked();
|
||||||
for (name, active_call, cx) in [
|
for (name, cx) in [("A", &cx_a), ("B", &cx_b), ("C", &cx_c), ("D", &cx_d)] {
|
||||||
("A", &active_call_a, &cx_a),
|
assert_eq!(
|
||||||
("B", &active_call_b, &cx_b),
|
followers_by_leader(project_id, cx),
|
||||||
("C", &active_call_c, &cx_c),
|
&[
|
||||||
("D", &active_call_d, &cx_d),
|
(peer_id_a, vec![peer_id_b, peer_id_c]),
|
||||||
] {
|
(peer_id_c, vec![peer_id_d])
|
||||||
active_call.read_with(*cx, |call, cx| {
|
],
|
||||||
let room = call.room().unwrap().read(cx);
|
"followers seen by {name}"
|
||||||
assert_eq!(
|
);
|
||||||
room.followers_for(peer_id_c, project_id),
|
|
||||||
&[peer_id_d],
|
|
||||||
"checking followers for C as {name}"
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Client C closes the project.
|
// Client C closes the project.
|
||||||
|
@ -278,32 +258,12 @@ async fn test_basic_following(
|
||||||
|
|
||||||
// Clients A and B see that client B is following A, and client C is not present in the followers.
|
// Clients A and B see that client B is following A, and client C is not present in the followers.
|
||||||
cx_c.foreground().run_until_parked();
|
cx_c.foreground().run_until_parked();
|
||||||
for (name, active_call, cx) in [("A", &active_call_a, &cx_a), ("B", &active_call_b, &cx_b)] {
|
for (name, cx) in [("A", &cx_a), ("B", &cx_b), ("C", &cx_c), ("D", &cx_d)] {
|
||||||
active_call.read_with(*cx, |call, cx| {
|
assert_eq!(
|
||||||
let room = call.room().unwrap().read(cx);
|
followers_by_leader(project_id, cx),
|
||||||
assert_eq!(
|
&[(peer_id_a, vec![peer_id_b]),],
|
||||||
room.followers_for(peer_id_a, project_id),
|
"followers seen by {name}"
|
||||||
&[peer_id_b],
|
);
|
||||||
"checking followers for A as {name}"
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// All clients see that no-one is following C
|
|
||||||
for (name, active_call, cx) in [
|
|
||||||
("A", &active_call_a, &cx_a),
|
|
||||||
("B", &active_call_b, &cx_b),
|
|
||||||
("C", &active_call_c, &cx_c),
|
|
||||||
("D", &active_call_d, &cx_d),
|
|
||||||
] {
|
|
||||||
active_call.read_with(*cx, |call, cx| {
|
|
||||||
let room = call.room().unwrap().read(cx);
|
|
||||||
assert_eq!(
|
|
||||||
room.followers_for(peer_id_c, project_id),
|
|
||||||
&[],
|
|
||||||
"checking followers for C as {name}"
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// When client A activates a different editor, client B does so as well.
|
// When client A activates a different editor, client B does so as well.
|
||||||
|
@ -1667,6 +1627,30 @@ struct PaneSummary {
|
||||||
items: Vec<(bool, String)>,
|
items: Vec<(bool, String)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn followers_by_leader(project_id: u64, cx: &TestAppContext) -> Vec<(PeerId, Vec<PeerId>)> {
|
||||||
|
cx.read(|cx| {
|
||||||
|
let active_call = ActiveCall::global(cx).read(cx);
|
||||||
|
let peer_id = active_call.client().peer_id();
|
||||||
|
let room = active_call.room().unwrap().read(cx);
|
||||||
|
let mut result = room
|
||||||
|
.remote_participants()
|
||||||
|
.values()
|
||||||
|
.map(|participant| participant.peer_id)
|
||||||
|
.chain(peer_id)
|
||||||
|
.filter_map(|peer_id| {
|
||||||
|
let followers = room.followers_for(peer_id, project_id);
|
||||||
|
if followers.is_empty() {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
Some((peer_id, followers.to_vec()))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
result.sort_by_key(|e| e.0);
|
||||||
|
result
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
fn pane_summaries(workspace: &ViewHandle<Workspace>, cx: &mut TestAppContext) -> Vec<PaneSummary> {
|
fn pane_summaries(workspace: &ViewHandle<Workspace>, cx: &mut TestAppContext) -> Vec<PaneSummary> {
|
||||||
workspace.read_with(cx, |workspace, cx| {
|
workspace.read_with(cx, |workspace, cx| {
|
||||||
let active_pane = workspace.active_pane();
|
let active_pane = workspace.active_pane();
|
||||||
|
|
Loading…
Reference in a new issue