cachetest

package
v0.43.2 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package cachetest owns behavior shared by Foundry's cache adapter acceptance.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(t *testing.T, setup func(*testing.T) (Backend, func(string) cache.EntryKey))

Run uses fresh owned addresses supplied by each adapter's test harness.

func RunBasicEntries

func RunBasicEntries(t *testing.T, setup func(*testing.T) (BasicEntryBackend, func(string) cache.EntryKey))

RunBasicEntries covers optional inspection/expiry independently of tags.

func RunContendedExpiry

func RunContendedExpiry(t *testing.T, prepare func(*testing.T) (AtomicExpiryBackend, *testkit.Clock, cache.EntryKey))

RunContendedExpiry holds the actual adapter lock while a competing metadata operation starts. The application clock advances without wall-clock sleeps. Reads take no mutation lock: Exists completes while the lock is held and evaluates liveness at its own observation time.

func RunEntries

func RunEntries(t *testing.T, setup func(*testing.T) EntryFixture)

func RunNamespace

func RunNamespace(t *testing.T, setup func(*testing.T) NamespaceFixture)

RunNamespace checks the same automatic typed-store contract in memory and Redis.

func RunPersistent

func RunPersistent(t *testing.T, setup func(*testing.T) PersistentFixture)

RunPersistent checks the file and PostgreSQL capacity, unusable-entry and namespace flush contracts.

func RunTagged

func RunTagged(t *testing.T, setup func(*testing.T) TaggedFixture)

Types

type AtomicExpiryBackend

type AtomicExpiryBackend interface {
	BasicEntryBackend
	Access(context.Context, cache.EntryKey, cacheatomic.Mode, cacheatomic.Change) error
}

type Backend

type Backend interface {
	cache.Backend
	cache.CounterBackend
}

type BasicEntryBackend

type BasicEntryBackend interface {
	Backend
	cache.EntryBackend
}

type EntryFixture

type EntryFixture struct {
	Backend EntryAdapter
	Key     func(string) cache.EntryKey
	Track   func(cache.EntryKey)
	// CorruptTagged replaces one exact owned payload with an invalid envelope.
	CorruptTagged func(cache.EntryKey)
}

type NamespaceFixture

type NamespaceFixture struct {
	Backend   TaggedBackend
	Namespace keyspace.Namespace
	Track     func(cache.EntryKey)
}

NamespaceFixture owns exact test addresses; no backend enumeration is needed.

type PersistentBackend

type PersistentBackend interface {
	BasicEntryBackend
	cache.FlushBackend
	Sweep(context.Context, int) (cacheatomic.PruneResult, error)
}

PersistentBackend is a durable adapter that reclaims expiry itself and invalidates a namespace by physical removal.

type PersistentFixture

type PersistentFixture struct {
	Open  func(t *testing.T, maxEntries, maxValueBytes int) PersistentBackend
	Clock *testkit.Clock
	Key   func(namespace keyspace.Namespace, logical string) cache.EntryKey
}

PersistentFixture opens backends over one shared durable store. Every opened backend reads expiry from Clock; Open varies only the entry and value bounds.

type TaggedBackend

type TaggedBackend interface {
	Backend
	cache.TaggedBackend
	cache.TaggedCounterBackend
}

type TaggedFixture

type TaggedFixture struct {
	Backend TaggedBackend
	Key     func(string) cache.EntryKey
	// Track registers exact derived payload addresses for adapter-owned cleanup.
	Track func(cache.EntryKey)
}

func (TaggedFixture) Snapshot

func (f TaggedFixture) Snapshot(t *testing.T, base cache.EntryKey, keys ...cache.EntryKey) cache.TaggedKey

Jump to

Keyboard shortcuts

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