mirror of
https://github.com/storytold/figcraft.git
synced 2026-11-12 08:51:11 +00:00
collab-net: hand the sync client the bounded roster; assert the kept prefixes
This commit is contained in:
1 parent
a40c76ab68
commit
2cfd2a3531
2 files changed
+28
-2
No files matched your search
@@ -4,7 +4,7 @@
|
||||
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use figcraft_collab::message::{Peer, Presence, ServerMsg};
|
||||
use figcraft_collab::message::{Access, CatchUp, Peer, Presence, Processed, ServerMsg};
|
||||
use figcraft_engine::live::{Event, MAX_PEERS};
|
||||
|
||||
use crate::guest::GuestConfig;
|
||||
@@ -69,7 +69,29 @@ fn a_hosts_long_names_and_colours_are_cut_where_they_are_kept() {
|
||||
let long = "x".repeat(100_000);
|
||||
take(ServerMsg::PeerJoined(Peer { client_id: 1, name: long.clone(), color: long }), &cfg, &inbox, &mut seen, &resume, &|| {});
|
||||
match inbox.drain().as_slice() {
|
||||
[Event::PeerJoined(p)] => assert!(p.name.chars().count() <= 256 && p.color.chars().count() <= 32),
|
||||
[Event::PeerJoined(p)] => assert_eq!((p.name.as_str(), p.color.as_str()), ("x".repeat(256).as_str(), "x".repeat(32).as_str())),
|
||||
other => panic!("{other:?}"),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_welcome_handed_to_the_sync_client_carries_the_bounded_roster() {
|
||||
let inbox = inbox();
|
||||
let cfg = GuestConfig::new(Invite::new("127.0.0.1:47900", "0123456789abcdef", "AbCdEfGhIjKlMnOpQrStUv"), "Ada".into());
|
||||
let resume = Mutex::new(None);
|
||||
let long = "y".repeat(100_000);
|
||||
let welcome = ServerMsg::Welcome {
|
||||
session: 1,
|
||||
client_id: 9,
|
||||
seq: 0,
|
||||
catch_up: CatchUp::Snapshot(Vec::new()),
|
||||
processed: Processed::default(),
|
||||
peers: vec![Peer { client_id: 1, name: long.clone(), color: long }],
|
||||
access: Access::default(),
|
||||
secret: 0,
|
||||
};
|
||||
take(welcome, &cfg, &inbox, &mut Seen::default(), &resume, &|| {});
|
||||
let events = inbox.drain();
|
||||
let Some(Event::Sync(ServerMsg::Welcome { peers, .. })) = events.iter().find(|e| matches!(e, Event::Sync(_))) else { panic!("{events:?}") };
|
||||
assert_eq!(peers.first().map(|p| (p.name.chars().count(), p.color.chars().count())), Some((256, 32)));
|
||||
}
|
||||
@@ -281,6 +281,10 @@ pub(crate) fn take(mut m: ServerMsg, cfg: &GuestConfig, inbox: &Inbox, seen: &mu
|
||||
view: None,
|
||||
};
|
||||
seen.peers = peers.clone();
|
||||
// The sync client keeps the roster of the welcome it is handed: the bounded one.
|
||||
if let ServerMsg::Welcome { peers: sent, .. } = &mut m {
|
||||
sent.clone_from(&peers);
|
||||
}
|
||||
seen.info = Some(info.clone());
|
||||
welcomed();
|
||||
inbox.push(Event::Welcome { info, peers });
|
||||
|
||||
Reference in new issue
Block a user