Package-level declarations

Types

Link copied to clipboard

Structure-unaware mutations of byte strings, for fuzz tests of decoders: bit flips, replaced, inserted and deleted bytes, duplicated prefixes and truncation. Start from valid encodings (RFC test vectors are ideal seeds) so mutations reach deep into the parser, and use a seeded Random so a failure reproduces.

Link copied to clipboard

What an InMemoryNetwork did with a datagram.

Link copied to clipboard

A byte stream side; writes arrive in pieces of at most the chunk size.

Link copied to clipboard
sealed interface InMemoryConnection

One side of an in-memory connection, for fault injection. Closing either side ends both: the other reads what is already on its way, then the end of the stream.

Link copied to clipboard

Accepts the connections InMemoryConnections.connector opens to its address.

Link copied to clipboard

Thrown by InMemoryConnections.connector when nobody listens at peer.

Link copied to clipboard

Thrown when reading from a connection that InMemoryConnection.reset broke.

Link copied to clipboard
class InMemoryConnections(chunkSize: Int = Int.MAX_VALUE)

In-memory connections for tests of CoAP over reliable transports (RFC 8323): listen binds a listener at an address, and connector connects to it, with a byte stream for coap+tcp and coaps+tcp or a message stream for coap+ws and coaps+ws. Delivery is immediate, ordered and lossless, as the transports promise; what a test needs beyond that it injects: InMemoryConnection.inject hands raw bytes to a side as if its peer had sent them, InMemoryConnection.reset breaks a connection.

Link copied to clipboard
class InMemoryDatagram(val from: Endpoint.Udp, val to: Endpoint, val bytes: ByteArray)

A datagram on its way through an InMemoryNetwork. bytes is the sender's copy; do not modify it.

Link copied to clipboard
sealed class InMemoryLink

One of the two ways a CoAP endpoint reaches a peer, in memory, so that one test runs over both and checks that the exchanges behave the same: Datagrams on an InMemoryNetwork (RFC 7252), Connections on InMemoryConnections (RFC 8323).

Link copied to clipboard

A message stream side; every message arrives whole, as a WebSocket frame.

Link copied to clipboard
class InMemoryNetwork(scope: CoroutineScope? = null, random: Random = Random(0))

A simulated datagram network for tests: every InMemoryTransport attached to it gets a UDP-style address and exchanges datagrams with the others in memory.

Link copied to clipboard
class InMemorySessions(transport: InMemoryTransport, identity: PeerIdentity = PeerIdentity.None) : DatagramTransport

A stand-in for a DTLS layer on an InMemoryTransport, for tests of what a CoAP endpoint does with secure sessions: every peer appears as an Endpoint.Secure, one session per address, authenticated as identity, and nothing is encrypted. endAll ends every session at once, as a DTLS layer reports sessions that closed (DatagramEvent.SessionEnded, RFC 7252 §9.1.1); a send to an ended session throws SessionEndedException, and the next datagram to or from the address opens a new session. Safe to use from any coroutine.

Link copied to clipboard
class LinkConditions(val lossRate: Double = 0.0, val duplicationRate: Double = 0.0, val latency: Duration = Duration.ZERO, val jitter: Duration = Duration.ZERO)

How an InMemoryNetwork treats each datagram: it may lose it, deliver it twice, or deliver it late. Different delays for consecutive datagrams reorder them, which is how reordering is simulated.

Link copied to clipboard
class RebindingTransport(val first: InMemoryTransport, val second: InMemoryTransport, val switchAt: Int, val oldAddressReceives: Boolean = true) : DatagramTransport

A DatagramTransport whose source address changes in the middle of a conversation, as a NAT rebinding does to a client behind it: datagrams go out from first until switchAt of them were sent, and from second after that, so the peer sees the later ones come from another address. Datagrams arrive on both addresses, unless oldAddressReceives is false: then whatever reaches first after the switch is lost, as when the old NAT binding has expired.

Link copied to clipboard
object Stress

Concurrency stress tests on real threads. Everything runs on Dispatchers.Default: a thread pool on the JVM and Kotlin/Native, the single event loop on JS and Wasm. The same common test therefore races threads where the platform has them, and interleaves at suspension points where it does not.

Link copied to clipboard
class StressScope : CoroutineScope

One iteration of Stress.run: a CoroutineScope whose coroutines the iteration waits for, the iteration's number, and a background scope for coroutines that outlive the body, such as those of an endpoint, like runTest's backgroundScope.