equivalence

package
v0.20.2 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package equivalence runs the same workload through two storage backends and asserts they produce equivalent results across every reader method.

The harness drives the canonical GrantRecord path through both the v3 Pebble engine and a reference implementation (a deterministic in-memory map). For each case we Put N grants, then for each reader method (GetGrantRecord, IterateGrants, IterateGrantsByEntitlement, IterateGrantsByPrincipal) we compare the returned set against the reference.

The runner is intentionally pluggable: additional engines can register as References when their adapters expose this contract.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotImplemented = errors.New("equivalence: reference doesn't implement this method")

ErrNotImplemented is returned by reference adapters that don't support a method.

Functions

func Compare

func Compare(ctx context.Context, refA, refB Reference, w Workload) error

Compare runs w against both refA and refB and returns nil if their outputs match. Used by the test driver to assert engine equivalence.

func Equal

func Equal(a, b *Result) error

Equal returns nil iff a and b are byte-equal Results, or a descriptive error otherwise. Used by the test driver to assert engine equivalence.

Types

type MemoryRef

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

MemoryRef is a deterministic in-memory implementation of Reference, used as the source-of-truth in equivalence tests. Backed by a nested map keyed by (sync_id, external_id). All operations are linearizable under MemoryRef.mu.

Iteration order is by external_id (lexicographic) for stable ordering across runs.

func NewMemoryRef

func NewMemoryRef() *MemoryRef

NewMemoryRef returns an empty in-memory reference.

func (*MemoryRef) DeleteGrantRecord

func (m *MemoryRef) DeleteGrantRecord(_ context.Context, externalID string) error

func (*MemoryRef) GetGrantRecord

func (m *MemoryRef) GetGrantRecord(_ context.Context, externalID string) (*v3.GrantRecord, error)

func (*MemoryRef) IterateGrants added in v0.15.0

func (m *MemoryRef) IterateGrants(_ context.Context, yield func(*v3.GrantRecord) bool) error

func (*MemoryRef) IterateGrantsByEntitlement

func (m *MemoryRef) IterateGrantsByEntitlement(_ context.Context, entitlementID string, yield func(*v3.GrantRecord) bool) error

func (*MemoryRef) IterateGrantsByPrincipal

func (m *MemoryRef) IterateGrantsByPrincipal(_ context.Context, principalRT, principalID string, yield func(*v3.GrantRecord) bool) error

func (*MemoryRef) PutGrantRecord

func (m *MemoryRef) PutGrantRecord(_ context.Context, r *v3.GrantRecord) error

func (*MemoryRef) SetCurrentSync

func (m *MemoryRef) SetCurrentSync(ctx context.Context, syncID string) error

type Op

type Op struct {
	Kind             OpKind
	Record           *v3.GrantRecord // nil for OpDelete
	DeleteExternalID string
}

Op is one operation in a workload.

type OpKind

type OpKind int

OpKind discriminates Op types.

const (
	OpPut OpKind = iota
	OpDelete
)

type Reference

type Reference interface {
	PutGrantRecord(ctx context.Context, r *v3.GrantRecord) error
	GetGrantRecord(ctx context.Context, externalID string) (*v3.GrantRecord, error)
	IterateGrants(ctx context.Context, yield func(*v3.GrantRecord) bool) error
	IterateGrantsByEntitlement(ctx context.Context, entitlementID string, yield func(*v3.GrantRecord) bool) error
	IterateGrantsByPrincipal(ctx context.Context, principalRT, principalID string, yield func(*v3.GrantRecord) bool) error
}

Reference is the minimal store contract the equivalence runner drives. Both the Pebble engine and the in-memory reference satisfy it; future SQLite + translation shims can be wired in by adding a new adapter.

type Result

type Result struct {
	BySyncCount        int
	ByEntitlementCount map[string]int
	ByPrincipalCount   map[string]int
	GetSpotChecks      map[string]bool // externalID -> present
}

Result is the per-Reference output collected at the end of a workload, in a form that's directly comparable across implementations.

func RunWorkload

func RunWorkload(ctx context.Context, ref Reference, w Workload) (*Result, error)

RunWorkload replays w against ref and collects a comparable Result. The runner is deterministic; running the same workload twice on the same reference must produce the same Result.

type Workload

type Workload struct {
	Name   string
	SyncID string
	Ops    []Op
}

Workload is a deterministic sequence of operations the runner replays into each Reference. Each op is replayed in order; the runner does not assume associativity or commutativity.

Jump to

Keyboard shortcuts

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