Wait for previous UpdateFollowers message ack before sending new ones

This commit is contained in:
Antonio Scandurra 2022-11-17 14:12:00 +01:00
parent 3b34d858b5
commit fe93263ad4
4 changed files with 106 additions and 57 deletions

View file

@ -4672,7 +4672,7 @@ async fn test_following(
cx_a: &mut TestAppContext,
cx_b: &mut TestAppContext,
) {
cx_a.foreground().forbid_parking();
deterministic.forbid_parking();
cx_a.update(editor::init);
cx_b.update(editor::init);
@ -4791,11 +4791,14 @@ async fn test_following(
workspace_a.update(cx_a, |workspace, cx| {
workspace.activate_item(&editor_a1, cx)
});
workspace_b
.condition(cx_b, |workspace, cx| {
workspace.active_item(cx).unwrap().id() == editor_b1.id()
})
.await;
deterministic.run_until_parked();
assert_eq!(
workspace_b.read_with(cx_b, |workspace, cx| workspace
.active_item(cx)
.unwrap()
.id()),
editor_b1.id()
);
// When client A navigates back and forth, client B does so as well.
workspace_a
@ -4803,49 +4806,74 @@ async fn test_following(
workspace::Pane::go_back(workspace, None, cx)
})
.await;
workspace_b
.condition(cx_b, |workspace, cx| {
workspace.active_item(cx).unwrap().id() == editor_b2.id()
})
.await;
deterministic.run_until_parked();
assert_eq!(
workspace_b.read_with(cx_b, |workspace, cx| workspace
.active_item(cx)
.unwrap()
.id()),
editor_b2.id()
);
workspace_a
.update(cx_a, |workspace, cx| {
workspace::Pane::go_forward(workspace, None, cx)
})
.await;
workspace_b
.condition(cx_b, |workspace, cx| {
workspace.active_item(cx).unwrap().id() == editor_b1.id()
workspace_a
.update(cx_a, |workspace, cx| {
workspace::Pane::go_back(workspace, None, cx)
})
.await;
workspace_a
.update(cx_a, |workspace, cx| {
workspace::Pane::go_forward(workspace, None, cx)
})
.await;
deterministic.run_until_parked();
assert_eq!(
workspace_b.read_with(cx_b, |workspace, cx| workspace
.active_item(cx)
.unwrap()
.id()),
editor_b1.id()
);
// Changes to client A's editor are reflected on client B.
editor_a1.update(cx_a, |editor, cx| {
editor.change_selections(None, cx, |s| s.select_ranges([1..1, 2..2]));
});
editor_b1
.condition(cx_b, |editor, cx| {
editor.selections.ranges(cx) == vec![1..1, 2..2]
})
.await;
deterministic.run_until_parked();
assert_eq!(
editor_b1.read_with(cx_b, |editor, cx| editor.selections.ranges(cx)),
vec![1..1, 2..2]
);
editor_a1.update(cx_a, |editor, cx| editor.set_text("TWO", cx));
editor_b1
.condition(cx_b, |editor, cx| editor.text(cx) == "TWO")
.await;
deterministic.run_until_parked();
assert_eq!(
editor_b1.read_with(cx_b, |editor, cx| editor.text(cx)),
"TWO"
);
editor_a1.update(cx_a, |editor, cx| {
editor.change_selections(None, cx, |s| s.select_ranges([3..3]));
editor.set_scroll_position(vec2f(0., 100.), cx);
});
editor_b1
.condition(cx_b, |editor, cx| {
editor.selections.ranges(cx) == vec![3..3]
})
.await;
deterministic.run_until_parked();
assert_eq!(
editor_b1.read_with(cx_b, |editor, cx| editor.selections.ranges(cx)),
vec![3..3]
);
// After unfollowing, client B stops receiving updates from client A.
assert_eq!(
workspace_b.read_with(cx_b, |workspace, cx| workspace
.active_item(cx)
.unwrap()
.id()),
editor_b1.id()
);
workspace_b.update(cx_b, |workspace, cx| {
workspace.unfollow(&workspace.active_pane().clone(), cx)
});