Show in the tests that a reconnect's replay is shown again, and what the passing ones prove

a_reconnect_finds_the_state_the_first_session_left passed for a narrower
reason than its comment said: the one message seen before the disconnect is
the newest one, so Dedup (which holds the messages up to 4 s older than the
last one it was asked about) still held it and dropped the host's replay.
With two messages more than 4 s apart the replay of the older one reaches the
user as a live Event::Chat, and no test saw it: the ignored test of the
stored rows used the same one-message setup.

- The ignored replay test is now two, over one scenario: two messages 10 s
  apart are seen, the session ends, a third is said while we are away, a
  second session connects. One asserts that only "while away" is shown (it
  sees ["first", "while away"]), the other that the history has each message
  once (it sees every row twice). The comments of the passing reconnect test
  say what it proves: a message inside Dedup's window is not shown again.
- the_chat_of_a_channel_is_resubscribed_when_we_move_back passed without the
  `seen` check of SessionLink for the same reason (the message seen before is
  the newest one Dedup holds). It now sees two messages 10 s apart before it
  moves away and fails with the check disabled ("before" comes again).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
faumarayandClaude Sonnet 5.5 committed 2026-10-24 04:13:13 +03:00
1 parent 2089f7ceba
commit 81d1de86e1
1 file changed
+102 -23
+102 -23
View File
@@ -768,8 +768,13 @@ async fn the_chat_of_a_channel_is_resubscribed_when_we_move_back() {
let chats: Vec<u64> = subscriptions(&handle).iter().map(|s| s.id).collect();
assert_eq!(chats, [GAMES, SERVER_CHAT]);
// Two messages more than `Dedup`'s 4 s apart, so that the copy of "before"
// that the second sync brings is not one `Dedup` would still recognise: it
// is the `seen` set of `SessionLink` that has to drop it.
host.put(entity(message(GAMES, ALICE_AUTHOR, "before", t))).unwrap();
assert_eq!(h.chat().await.text, "before");
host.put(entity(message(GAMES, ALICE_AUTHOR, "before too", t + 10_000))).unwrap();
assert_eq!(h.chat().await.text, "before too");
h.engine.send(Command::MoveToChannel { session: SESSION, channel: LOBBY, password: None });
h.state(|s| s.own_channel == Some(LOBBY)).await;
@@ -779,7 +784,7 @@ async fn the_chat_of_a_channel_is_resubscribed_when_we_move_back() {
})
.await;
// Said while we were away: nobody of ours listens to the games chat.
host.put(entity(message(GAMES, BOB_AUTHOR, "while away", t + 5_000))).unwrap();
host.put(entity(message(GAMES, BOB_AUTHOR, "while away", t + 30_000))).unwrap();
h.engine.send(Command::MoveToChannel { session: SESSION, channel: GAMES, password: None });
h.state(|s| s.own_channel == Some(GAMES)).await;
@@ -1275,8 +1280,15 @@ async fn media_routes_to_the_talker_of_its_slot() {
/// A second `ConnectVoice` replaces the session: the host sees the first one
/// closed, the second finds the state the first left (a message said while we
/// were away comes, one we had seen does not come again), and the participant
/// of the second session is another one.
/// were away comes), and the participant of the second session is another one.
///
/// What this proves about the replay is narrow: the one message seen before
/// the disconnect is not shown again because `Dedup` still holds it (it is the
/// newest message the engine saw, and `Dedup` keeps the messages up to 4 s
/// older than the last one it was asked about), so the copy the host's sync
/// brings is dropped. A replayed message older than that is shown again, and
/// every replayed message is stored again: the two ignored tests below pin
/// both (F3, `docs/session-seam.md` 16.5).
#[tokio::test(flavor = "multi_thread")]
async fn a_reconnect_finds_the_state_the_first_session_left() {
let mut h = Harness::start();
@@ -1297,6 +1309,9 @@ async fn a_reconnect_finds_the_state_the_first_session_left() {
let second = h.connect().await;
assert_eq!(h.connector.connects().len(), 2);
assert_eq!(h.connector.sessions().len(), 2);
// The window of the CHAT scope comes again, "before" with it. It is not
// shown only because `Dedup` still holds it, the newest message seen; a
// message older than `Dedup`'s 4 s would be shown (the ignored tests below).
assert_eq!(h.chat().await.text, "while away");
assert_eq!(h.state.own_client, Some(second.participant_id() as u16));
assert_ne!(second.participant_id(), first.participant_id());
@@ -1311,7 +1326,9 @@ async fn a_reconnect_finds_the_state_the_first_session_left() {
.collect();
assert!(!seats.contains(&first.participant_id()), "{seats:?}");
assert!(seats.contains(&second.participant_id()), "{seats:?}");
// (That the history has each message once is the next test's business.)
// (That the history has each message once, and that a replayed message
// older than `Dedup`'s 4 s is not shown again, are the business of the
// ignored tests below.)
// Connecting while connected replaces the session at once.
h.ask_connect();
@@ -1323,33 +1340,95 @@ async fn a_reconnect_finds_the_state_the_first_session_left() {
assert_eq!(second.close_reason(), Some(CloseReason::Local(v1::CloseCode::Normal)));
}
/// A message a host sends again when a session reconnects (the full sync of a
/// CHAT scope repeats its window) is one message in the history.
/// What a host that sends the window of a CHAT scope again makes of a
/// reconnect. Two messages more than `Dedup`'s 4 s apart are said and seen,
/// the session ends, a third is said while we are away, and a second session
/// connects. Returns the harness and the texts the engine showed as live chat
/// messages from the second connect until the third had come, and what was
/// still to come when a notice that the host told after them arrived.
///
/// Known limit, found by this test and left for the resume of
/// `docs/session-seam.md` (H8, section 16): the engine reports a message once
/// per connection (`seen` in `SessionLink` is per connection), shows it once
/// (`Dedup` in `session.rs` drops the copy), but stores the copy: the store
/// merges copies that come from different sources only, so a replay over the
/// same source is a second row. TeamSpeak never replays, so no host the
/// engine reaches today meets this; a `voelin://` host will.
#[tokio::test(flavor = "multi_thread")]
#[ignore = "known limit: a v1 host's replay after a reconnect is stored twice (docs/session-seam.md 16)"]
async fn a_message_the_host_sends_again_after_a_reconnect_is_stored_once() {
/// The window is replayed oldest first (by id), so "while away" is its last
/// message, and whatever precedes it in the result is a replayed message that
/// the engine showed again.
async fn a_reconnect_to_a_host_that_replays() -> (Harness, Vec<String>) {
let mut h = Harness::start();
let _first = h.connect().await;
let first = h.connect().await;
let host = h.host();
let t = now_ms();
h.host().put(entity(message(GAMES, ALICE_AUTHOR, "before", t))).unwrap();
assert_eq!(h.chat().await.text, "before");
host.put(entity(message(GAMES, ALICE_AUTHOR, "first", t))).unwrap();
host.put(entity(message(GAMES, ALICE_AUTHOR, "second", t + 10_000))).unwrap();
assert_eq!(h.chat().await.text, "first");
assert_eq!(h.chat().await.text, "second");
h.engine.send(Command::DisconnectVoice { session: SESSION });
h.state(|s| s.voice == VoiceState::Disconnected).await;
h.host().put(entity(message(GAMES, BOB_AUTHOR, "while away", t + 30_000))).unwrap();
let _second = h.connect().await;
assert_eq!(h.chat().await.text, "while away");
eventually(WAIT, "the host to see the first session closed", || first.close_reason().is_some())
.await;
host.put(entity(message(GAMES, BOB_AUTHOR, "while away", t + 30_000))).unwrap();
let second = h.connect().await;
let mut shown = Vec::new();
while shown.last().map(String::as_str) != Some("while away") {
shown.push(h.chat().await.text);
}
// Everything the host's sync had to say is behind us; a notice it tells now
// comes after whatever the engine still reports.
notice(&second, "sync marker");
loop {
let more = h
.next(|e| match e {
Event::Chat { message, .. } => Some(Some(message.text)),
Event::Error { message, .. } if message == "sync marker" => Some(None),
_ => None,
})
.await;
match more {
Some(text) => shown.push(text),
None => return (h, shown),
}
}
}
/// The messages a host sends again when a session reconnects are not shown
/// again: the engine shows "while away" and nothing else.
///
/// Known limit, found by this test and left for the resume of
/// `docs/session-seam.md` (H8, 16.5): the engine is told every message of a
/// replayed window again (`seen` in `SessionLink` is per connection), and
/// `Dedup` in `session.rs` drops one only while an equal message (target,
/// author, text, a timestamp within 2 s) is still held, and it holds the
/// messages up to 4 s older than the last one it was asked about. "second",
/// the newest message seen before the disconnect, is held and its replay is
/// dropped; "first", 10 s older, is not, and is shown again as a live
/// `Event::Chat` (this test sees `["first", "while away"]`). The one message
/// of `a_reconnect_finds_the_state_the_first_session_left` is inside the
/// window, which is all that test proves. TeamSpeak never replays, so no host
/// the engine reaches today meets this; a `voelin://` host will.
#[tokio::test(flavor = "multi_thread")]
#[ignore = "known limit: a v1 host's replay after a reconnect is shown again (docs/session-seam.md 16.5)"]
async fn a_message_the_host_sends_again_after_a_reconnect_is_not_shown_again() {
let (_h, shown) = a_reconnect_to_a_host_that_replays().await;
assert_eq!(shown, ["while away"]);
}
/// The messages a host sends again when a session reconnects are one message
/// each in the history.
///
/// Known limit, found by this test and left for the same resume (H8, 16.5):
/// the engine stores every message it is told, shown or not (`store_live` runs
/// before `Dedup`), and the store merges copies that come from different
/// sources only, so a replay over the same source is a second row, whether
/// `Dedup` hid the copy from the display or not (this test sees `["first",
/// "first", "second", "second", "while away"]`). A `ChatMessage` does not carry
/// the host's message id that would let the store merge them.
#[tokio::test(flavor = "multi_thread")]
#[ignore = "known limit: a v1 host's replay after a reconnect is stored twice (docs/session-seam.md 16.5)"]
async fn a_message_the_host_sends_again_after_a_reconnect_is_stored_once() {
let (h, _) = a_reconnect_to_a_host_that_replays().await;
// The history thread takes its jobs in order: every row the engine was told
// to write before it showed "while away" is written when this page is read.
let rows = h.stored(ChatTarget::Channel(GAMES)).await;
let texts: Vec<_> = rows.iter().map(|m| m.message.text.as_str()).collect();
assert_eq!(texts, ["before", "while away"]);
assert_eq!(texts, ["first", "second", "while away"]);
}
/// A connect that fails is a disconnect with the reason the connector gave.