FakeRoom
A test double for Room with test-driver helpers for roster manipulation, event delivery, and outgoing-frame inspection.
Defaults make FakeRoom() a ready-to-use, host-role, empty-roster room in one line:
val room = FakeRoom()
room.addMember(Member(PeerId("alice"), identity("alice"), DeviceKey.generate().id, Liveness.Connected))
room.deliver(PeerId("alice"), byteArrayOf(1, 2, 3))
val frame = room.incoming.first()For wired two-room scenarios, prefer fakeRoomPair which cross-wires broadcast delivery between two rooms.
Send semantics (matching the Room contract):
Before leave, raw broadcast and sendTo refuse protocol-classified payloads with ReservedRoomPrefix. Channel views accept arbitrary payload bytes.
broadcast and sendTo after leave are silent no-ops (matching the contract's behaviour after MembershipEvent.HostLost).
Stream semantics — a deliberate divergence from the real Room. The real Room documents events and incoming as hot, no-replay streams (late collectors miss history). For test ergonomics this double backs them with bounded, backpressured channels instead, so deliver(...) followed by incoming.first() works without racing a collector (capacity DeliveryPolicy.DEFAULT_CAPACITY). FakeChannelSeam.incoming is backed by a Spool using channelPolicy. Two consequences a consumer should not encode as Room guarantees:
frames/events emitted before collection are buffered and replayed here, whereas the real Room would drop them;
leave completes events/incoming (channel close), whereas the real Room cancels its backing scope without completing the flows.
incomingFrom is not a divergence: it follows the real room's per-admission contract. An inbox opens when addMember admits a member and is fed by deliver only while that member is on the roster; removeMember and leave complete its flow; a member with no current admission reads as an empty, completed stream; an unclaimed overflow followed by a claim, and a claimed overflow, fail it with FramesLost; a concurrent second collection throws.
Constructors
Types
A Seam view returned by FakeRoom.channel.
Properties
Accepted raw and channel broadcast payloads, in call order.
What flush answers while this room is live. Defaults to FlushOutcome.Drained, since this fake records a send before returning and holds no queue. Set it to drive a consumer's other paths, in particular the FlushOutcome.TimedOut and FlushOutcome.Unsupported arms a real fabric reaches.
Functions
Add member to the roster and emit MembershipEvent.Joined.
Returns a Seam view scoped to channel id, backed by _rosterPeers for admit-gated peer visibility and a bounded Spool for test-driver frame delivery via FakeChannelSeam.deliver.
Returns the FakeChannelSeam for id if it has been created, or null otherwise.
Push a raw MembershipEvent onto the events channel. Useful for events not covered by the named helpers.
Emit MembershipEvent.Resumed for peerId (a partitioned joiner has reconnected within the window).
A room that has left answers FlushOutcome.Failed, as the real room does.
Emit MembershipEvent.HostLost (terminal event on a joiner's room), then leave, as the real room does. After this, broadcast and sendTo become silent no-ops per the contract, the roster is empty and every incomingFrom flow has completed. A no-op on a room that has already left.
Emit MembershipEvent.WindowOpened (host-side signal that a joiner's reconnect window has opened, expiring at expiresAt).
Flip the named member's Liveness to Liveness.Partitioned and emit MembershipEvent.Partitioned.
Flip the named member's Liveness back to Liveness.Connected and emit MembershipEvent.Recovered.
Remove the member with peerId from the roster and emit MembershipEvent.Left. No-op if the peer is not in the roster.
Test hook: set the attested-principals roster this fake room reports.
Drive this fake's own self-reachability (Room.localFabric), emitting the matching edge.
Transition the seam state to SeamState.Torn. Channel views forward their state from this room's seam, so tearing the seam winds down any us.tractat.kuilt.crdt.replicator.Quilter subscribed to the channel. A no-op once the seam is torn, by this or by leave: the first reason stands.