consumertest

package
v0.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 18, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package consumertest is the contract suite that every consumer Runtime (Pg and in-memory) must pass. A runtime test calls

consumertest.Run(t, func(t *testing.T, codec *eventstore.Codec) consumertest.Backend { ... })

and the suite exercises it only through the public consumer API.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(t *testing.T, newBackend func(t *testing.T, codec *eventstore.Codec) Backend, opts ...Option)

Run runs the contract suite. newBackend is called once per case with the codec the Store must encode with.

Types

type Backend

type Backend struct {
	// Store and UnitOfWork write events; Store encodes with the suite's
	// codec.
	Store      eventstore.Store
	UnitOfWork eventstore.UnitOfWork
	Runtime    consumer.Runtime
	Effects    Effects
	// Restart returns a new Runtime over the same log and Cursors, as after
	// a process restart. Runtimes it returned earlier are no longer used.
	Restart func(t *testing.T) consumer.Runtime
}

Backend is one empty event log with a Runtime over it.

type Effects

type Effects interface {
	Record(ctx context.Context, key string) error
	// Keys returns the committed keys in record order.
	Keys(ctx context.Context) ([]string, error)
}

Effects is a read model a handler writes to. Record joins the Cursor transaction in ctx, so a rolled-back transaction drops its records.

type InMemoryEffects

type InMemoryEffects struct {
	// contains filtered or unexported fields
}

InMemoryEffects is Effects for in-memory backends; Record stages its write with postgres.Stage.

func (*InMemoryEffects) Keys

func (e *InMemoryEffects) Keys(context.Context) ([]string, error)

Keys returns the committed keys.

func (*InMemoryEffects) Record

func (e *InMemoryEffects) Record(ctx context.Context, key string) error

Record stages key.

type Option

type Option func(*config)

Option configures Run.

func InBubble

func InBubble() Option

InBubble runs every case and its newBackend inside a testing/synctest bubble, so retries and Age use fake time. For in-memory backends.

func Sequential

func Sequential() Option

Sequential runs the cases one after another. For Pg backends whose databases share one cluster: pg_snapshot_xmin is cluster-wide, so a transaction of a parallel case would hide fresh events from Drain.

type PgEffects

type PgEffects struct {
	// contains filtered or unexported fields
}

PgEffects is Effects for Pg backends. Record inserts through postgres.Conn, so it joins the Cursor transaction in ctx.

func NewPgEffects

func NewPgEffects(t *testing.T, pool *pgxpool.Pool) *PgEffects

NewPgEffects creates the effects table in pool's database.

func (*PgEffects) Keys

func (e *PgEffects) Keys(ctx context.Context) ([]string, error)

Keys returns the committed keys.

func (*PgEffects) Record

func (e *PgEffects) Record(ctx context.Context, key string) error

Record inserts key.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL