recordstoretest

package
v0.1.37 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package recordstoretest is the conformance suite every recordstore.Backend runs, so the kv, sqlite and ndjson backends can never disagree about what appending, scanning, expiring and describing a stream mean.

Index

Constants

View Source
const (
	// Kind is the kind most conformance streams are written under: unkeyed,
	// kept whole until the stream expires.
	Kind = "sample"

	// KeyedKind holds each name once per stream.
	KeyedKind = "keyed"

	// RollingKind holds each name once and keeps each row TTL after its append.
	RollingKind = "rolling"
)
View Source
const ExpiryTTL = 200 * time.Millisecond

ExpiryTTL is the ttl the expiry spec sets. It is short because the in-process kv store expires against the wall clock, so its Elapse sleeps.

View Source
const RecheckInterval = 20 * time.Millisecond

RecheckInterval is how often a conformance tail confirms its stream still exists. It is short so the expiry spec ends within the suite's patience.

View Source
const TTL = time.Hour

TTL is the stream ttl every conformance backend is opened with.

Variables

View Source
var Columns = []query.ColumnDef{
	{Name: "name", Type: query.ColumnTypeString},
	{Name: "count", Type: query.ColumnTypeNumber},
	{Name: "ok", Type: query.ColumnTypeBoolean},
	{Name: "detail", Type: query.ColumnTypeJSON},
}

Columns is the columns of every conformance kind, for a backend that stores rows by column.

Functions

func Conformance

func Conformance(open func() Harness)

Conformance registers the suite. open is called before every spec.

func Normalize

func Normalize(rows []recordstore.Row) []recordstore.Row

Normalize is rows as their JSON encoding reads back, which is the only equality a row promises across backends: an int written may read back as a float, and a nested value as generic maps.

func SampleRow

func SampleRow(n int) recordstore.Row

SampleRow is the n-th conformance row.

func SampleRows

func SampleRows(first, last int) []recordstore.Row

SampleRows are rows first..last.

func Scanned

func Scanned(backend recordstore.Backend, stream string, afterSeq int64) ([]int64, []recordstore.Row)

Scanned is every row a stream holds after afterSeq, keyed by seq.

func Schema

func Schema(kind string) (recordstore.KindSchema, error)

Schema resolves the conformance kinds and refuses every other kind.

Types

type Harness

type Harness struct {
	// Backend is a fresh, empty backend, opened with Schema and TTL.
	Backend recordstore.Backend

	// Elapse moves the backend's clock forward by d and reaps whatever that
	// expired, so a stream whose ttl is shorter than d is gone afterwards.
	Elapse func(d time.Duration)

	// Advance moves the backend's clock forward by d and reaps nothing, so
	// what a spec sees after it is only what the backend itself decided.
	Advance func(d time.Duration)

	// Now reads the backend's clock.
	Now func() time.Time

	// Reopen opens another backend over the storage Backend wrote, sharing
	// its clock, as a process restarting would.
	Reopen func() recordstore.Backend
}

Harness opens the backend under test.

Jump to

Keyboard shortcuts

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