Connectum API Reference / @connectum/events-amqp / testing
testing
Programmable AMQP test double — the @connectum/events-amqp/testing subpath (#203).
FakeAmqpAdapter models the REAL adapter's observable contracts without a broker and without importing amqplib at runtime:
- the typed error taxonomy (
AmqpConnectionError,AmqpTopologyError, …) — inject outcomes per publish via FakeAmqpControl.nextPublish, includingAmqpPublishTimeoutError: the state-UNKNOWN outcome that no real broker (or even Toxiproxy) reproduces deterministically; - the canonical lifecycle union (AmqpLifecycleCallbacks.onLifecycle) INCLUDING the deprecated flat-callback shim — events go through the real adapter's dispatch, so ordering, shim payloads, and exception isolation match the real adapter by construction;
- the state machine:
connect()on a live or recovering (or dead retries-exhausted) adapter throwsalready connectedlike the real one; a mid-recoverysubscribe()PARKS and settles with the recovery outcome; the probe-then-recoverconnect()semantics gate onAmqpTopologyErrorexactly like the real probe.
Deliberately NOT modeled (documented divergences):
- timing: there is no backoff — recovery advances only via explicit FakeAmqpControl.completeRecovery / FakeAmqpControl.exhaustRecovery calls, and
reconnecting.delayis always0; - a queued topology
failSetupatconnect()WITHOUT fail-fast reportssetup-failed { initial: true }and then connects anyway (the real adapter would keep retrying inside recovery); a NON-topology queued failure atconnect()is consumed silently and the connect proceeds (the real adapter treats it as transient and blocks in recovery); - broker-driven settlement: handler
ack/nackcalls are RECORDED (see the FakeAmqpControl.deliver result) but do not drive redelivery — re-deliver explicitly with a higherattemptto model it. Handler rejections are swallowed exactly like the real consumer (which nacks for redelivery instead of propagating); - the wire-level envelope: FakeAmqpControl.published records the bus-facing call as the adapter received it. Wire fidelity is the real adapter's integration-tested domain. Incoming envelope headers ARE handled with parity:
deliver()honorsx-event-id/x-published-atand strips the internal keys from handler-visible metadata.
