Testing

Asynchronous I/O code is notoriously difficult to test. Real network operations introduce latency, non-determinism, and dependencies on external services — all of which make tests slow and fragile. Corosio provides test utilities that replace live networking with controllable, deterministic substitutes. You can stage data for reads, verify what your code writes, and force short reads or writes — all without opening a single network connection. This section covers the tools and patterns that make thorough testing of I/O code practical and repeatable.

What’s in this section

  • Mock Socketsmocket, make_mocket_pair, and the staging API for byte-level deterministic tests.

  • Socket Pairsmake_socket_pair for tests that need real socket semantics (TLS, set_option, shutdown, true EOF).

  • Testing Patterns — recipes that combine the two facilities.

Choosing the right tool

Goal Use

Byte-level expectations, staged responses, no real network

mocket

Real socket semantics — TLS handshake, SO_* options, shutdown ordering, EOF

socket_pair

Combine the two (e.g., framing on top of TLS over a real socket)

See Patterns