sendtest

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Overview

Package sendtest drives campaign sends end to end in tests: the real API's data, the sending engine on a virtual clock and the demo transport whose delivery and engagement events go through the same normalization as provider webhooks. Reports, Send Readiness and the live monitor are tested on what production writes, not on demo rows (review F-5).

Index

Constants

View Source
const (
	// FaultOK takes every message and answers.
	FaultOK = "ok"
	// FaultTakeNoAnswer takes the messages, then never answers: the call
	// ends with the engine's call timeout.
	FaultTakeNoAnswer = "take_no_answer"
	// FaultHold takes the messages once the test closes Release, then
	// answers; Started is signalled when a call arrives.
	FaultHold = "hold"
	// FaultRefuse refuses the call with a 503 the provider answered.
	FaultRefuse = "refuse"
	// FaultFlaky refuses every other call with a 503 and takes the rest.
	FaultFlaky = "flaky"
	// FaultThrottle answers 429: the account sends too fast.
	FaultThrottle = "throttle"
	// FaultQuota answers that the account's daily quota is used up.
	FaultQuota = "quota"
	// FaultIdentity refuses every message: the sender isn't verified.
	FaultIdentity = "identity"
)

Fault modes.

Variables

View Source
var Fault = &FaultState{}

Fault is the fault providers' shared state.

Functions

This section is empty.

Types

type ContactSpec

type ContactSpec struct {
	N        int
	Mailbox  string
	Domain   string
	Tier     string
	Source   string
	Engaged  bool
	Status   string
	Suppress bool
	Paused   bool
	Role     bool
	// Alias makes the batch plus-tagged aliases of the fixture's first
	// contacts (same domain): the same mailboxes.
	Alias bool
	// RolePattern gives the batch role addresses (info+…@) without the flag.
	RolePattern bool
	// Stopped: the sunset policy stopped their Broadcasts.
	Stopped bool
	// StoppedPair adds, for each contact (Stopped), a newer active alias.
	StoppedPair bool
	// Unclassified leaves the mailbox provider to the classifier, which
	// looks the domain's MX record up when the send starts; otherwise
	// Mailbox is final.
	Unclassified bool
}

ContactSpec describes a batch of test contacts.

type FaultState

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

FaultState is what the fault providers do and what they took.

func (*FaultState) Calls

func (f *FaultState) Calls() int

Calls is how many Send calls arrived.

func (*FaultState) Release

func (f *FaultState) Release()

Release lets the calls held in FaultHold go.

func (*FaultState) Reset

func (f *FaultState) Reset(mode string)

Reset sets the mode and forgets what was taken.

func (*FaultState) SetIPs

func (f *FaultState) SetIPs(ips ...string)

SetIPs sets the dedicated IPs faultesp-ips lists; none is a shared pool.

func (*FaultState) SetMode

func (f *FaultState) SetMode(mode string)

SetMode changes what the providers do, keeping what they took.

func (*FaultState) Started

func (f *FaultState) Started() <-chan struct{}

Started is signalled when a call arrives in FaultHold.

func (*FaultState) Took

func (f *FaultState) Took() map[uuid.UUID]int

Took is how many times the provider took each message (a delivery).

func (*FaultState) TookFor

func (f *FaultState) TookFor(address string) int

TookFor is how many messages the provider took for an address.

type Fixture

type Fixture struct {
	*Suite
	T        *testing.T
	List     uuid.UUID
	Campaign uuid.UUID
}

Fixture is one scenario: a copy of Weekly Digest #142 (content, sender, A/B test) sending to a list of the scenario's own contacts.

func (*Fixture) AddContacts

func (f *Fixture) AddContacts(specs ...ContactSpec)

AddContacts inserts contacts in the fixture's list.

func (*Fixture) Count

func (f *Fixture) Count(sql string, args ...any) int64

Count runs a counting query or fails the test.

func (*Fixture) Counts

func (f *Fixture) Counts() map[string]int64

Counts are the fixture's campaign counters, summed over its cells, by column name (sent, delivered, opened_human…).

func (*Fixture) Drive

func (f *Fixture) Drive(d time.Duration) (time.Time, bool)

Drive runs the send for d of virtual time from the fixture's start and returns where it stopped and whether the send ended.

func (*Fixture) DriveWithout

func (f *Fixture) DriveWithout(d time.Duration, kinds ...string) (time.Time, bool)

DriveWithout is Drive with what the demo transport plans of these kinds (delivered, deferred, hard_bounce, soft_bounce, complaint, open, click; every kind with none) dropped before any of it comes due, so the test scripts those outcomes itself. Like Drive, it steps the engine once a second, sending and then applying the events due by then; but it drives each second only for a moment, since a send that ends applies the events due by the end of its drive. An event comes due 0.6 s after its message went out at the earliest, so what a step's sends planned is dropped before anything can apply it.

func (*Fixture) Dump

func (f *Fixture) Dump()

Dump logs the send's state when a test fails.

func (*Fixture) Exec

func (f *Fixture) Exec(sql string, args ...any)

Exec runs SQL or fails the test.

func (*Fixture) HandedOver

func (f *Fixture) HandedOver(specs ...ContactSpec) []uuid.UUID

HandedOver sends the fixture's campaign to its contacts (without the A/B test) until every message is with a provider, and drops what the demo transport plans for them before any of it comes due (a chance bounce or complaint would suppress the address), so a test scripts their deliveries, opens and clicks itself. It returns the messages in id order.

func (*Fixture) ProviderID

func (f *Fixture) ProviderID(adapter string) uuid.UUID

ProviderID is the workspace's connected provider of an adapter.

func (*Fixture) StartSend

func (f *Fixture) StartSend(o engine.StartOptions)

StartSend starts the send now and builds its audience.

func (*Fixture) Status

func (f *Fixture) Status() string

Status is the campaign's status.

func (*Fixture) UseFaultProvider

func (f *Fixture) UseFaultProvider(dedupe bool) uuid.UUID

UseFaultProvider connects a fault provider to the workspace and sends the fixture's campaign through it alone. It returns the provider's id.

func (*Fixture) UseFaultSMTP

func (f *Fixture) UseFaultSMTP() uuid.UUID

UseFaultSMTP is UseFaultProvider with a provider that reports no deliveries, as plain SMTP doesn't.

func (*Fixture) UseReportingProvider

func (f *Fixture) UseReportingProvider() uuid.UUID

UseReportingProvider is UseFaultProvider with a provider whose API lists the account's dedicated IPs (Fault.SetIPs), on the shared pool until someone asks it.

type Suite

type Suite struct {
	Env   *apptest.Env
	E     *engine.Engine
	Ctx   context.Context
	WS    uuid.UUID
	Sofia uuid.UUID
	Start time.Time
	// contains filtered or unexported fields
}

Suite is one seeded demo shared by a test's scenarios, with the sending engine on a virtual clock that starts at Start.

func NewSuite

func NewSuite(t *testing.T) *Suite

NewSuite seeds the demo (once per test run) and builds the engine.

func (*Suite) Fixture

func (s *Suite) Fixture(t *testing.T, name string) *Fixture

Fixture makes a copy of Weekly Digest #142 (content, sender, A/B test) that sends to a list of the test's own contacts.

Jump to

Keyboard shortcuts

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