Skip to content

Connectum API Reference / @connectum/events-amqp / testing

testing ​

Programmable AMQP test double for the @connectum/events-amqp/testing subpath.

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, including AmqpPublishTimeoutError: 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 consumer-loss events (consumer-lost, consumer-restored): the broker ending a consumer on a live connection is driven by FakeAmqpControl.loseConsumer / FakeAmqpControl.restoreConsumers;
  • the state machine: connect() on a live or recovering adapter throws already connected like the real one, while an adapter whose recovery gave up accepts a fresh connect() without its old subscriptions; a mid-recovery subscribe() PARKS and settles with the recovery outcome; the probe-then-recover connect() semantics gate on AmqpTopologyError exactly like the real probe;
  • exchange-type routing: deliver() follows the configured exchangeType (fanout and headers queues receive every message, the EventBus alone picks handlers) and subscribe() validates patterns for that type and topologyMode exactly like the real adapter.

Deliberately NOT modeled (documented divergences):

  • declared header bindings: topology is not modeled, so a headers fake delivers every message, while the real adapter delivers only what the x-match bindings declared for the queue in topology.bindings select;
  • timing: there is no backoff — recovery advances only via explicit FakeAmqpControl.completeRecovery / FakeAmqpControl.exhaustRecovery calls, and reconnecting.delay is always 0; a lost consumer comes back through FakeAmqpControl.restoreConsumers (always attempt 1, never consumer-restore-failed, the queue name never changes) or silently through FakeAmqpControl.completeRecovery, as connection recovery does;
  • consumer loss is queue-wide: FakeAmqpControl.loseConsumer takes every live subscription on the queue (a group shared by several subscriptions loses all of them), whatever the cause; a real channel-closed ends one subscription's channel only, a deleted queue ends every consumer on it;
  • a queued topology failSetup at connect() WITHOUT fail-fast reports setup-failed { initial: true } and then connects anyway (the real adapter would keep retrying inside recovery); a NON-topology queued failure at connect() is consumed silently and the connect proceeds (the real adapter treats it as transient and blocks in recovery);
  • broker-driven settlement: handler ack/nack calls are RECORDED, at most one per delivery per handler (the first wins, as in the real adapter; see the FakeAmqpControl.deliver result) but do not drive redelivery — re-deliver explicitly with a higher attempt to 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() honors x-event-id/x-published-at and strips the internal keys from handler-visible metadata.

Interfaces ​

Type Aliases ​

Functions ​