FaultySeam

class FaultySeam(delegate: Seam, scope: CoroutineScope, initialProfile: FaultProfile = FaultProfile.Healthy) : Seam

A Seam wrapper that injects configurable faults for use in tests.

Faults are driven by a FaultProfile which can be swapped atomically at any point during a test via setFaultProfile. The profile change takes effect on the next frame — frames already in-flight at the moment of the switch complete under the old profile.

Determinism guarantee: every probabilistic and randomised fault takes an explicit seed. No wall-clock time is consumed — delays go through kotlinx.coroutines.delay so kotlinx.coroutines.test.runTest controls virtual time.

Inspection hooks: framesDropped, framesDelayed, and framesDelivered counters are updated atomically so tests can assert on fault behaviour without inspecting internal channels.

Consumed by partition / reconnect test suites. Exposes the same Seam contract as InMemoryLoom-produced links.

Constructors

Link copied to clipboard
constructor(delegate: Seam, scope: CoroutineScope, initialProfile: FaultProfile = FaultProfile.Healthy)

Properties

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
open override val incoming: Flow<Swatch>

Frames received from peers, in send order, delivered to a single collector. Cold/single-collection semantics: collect once per Seam; fan-out consumers wrap with shareIn. A second concurrent collector is unsupported and will race.

Link copied to clipboard
open override val peers: StateFlow<Set<PeerId>>

Live set of peers currently connected. Includes selfId.

Link copied to clipboard
open val plies: StateFlow<Map<PlyId, SeamState>>

Per-ply lifecycle breakdown. Single-ply fabrics report a one-entry map keyed by PlyId.Sole. Invariant: state.value equals the rollup of plies.value.values under "any ply Woven ⇒ Woven".

Link copied to clipboard
open override val selfId: PeerId

This peer's own identifier.

Link copied to clipboard
open override val state: StateFlow<SeamState>

The fabric's lifecycle as observed by this peer.

Functions

Link copied to clipboard
open suspend override fun broadcast(payload: ByteArray)

Send to all other peers. Suspends until accepted by the local transport.

Link copied to clipboard
open suspend override fun close(reason: CloseReason = CloseReason.Normal)

Disconnect from the session. Idempotent.

Link copied to clipboard
fun heal()
Link copied to clipboard
fun partition(direction: Direction = Direction.Both)
Link copied to clipboard
open suspend override fun sendTo(peer: PeerId, payload: ByteArray)

Send to one peer. Suspends until accepted by the local transport.

Link copied to clipboard

Replace the active FaultProfile atomically.