alloctest

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package alloctest provides allocators that refuse on purpose, and the two loops SQLite runs against them.

It is an ordinary package rather than a set of _test.go helpers, for the same reason pkg/vfs/vfstest is: a test in any package installs one through the published API a production caller would use, so the code under test is the code that ships.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Sweep

func Sweep(t *testing.T, mode Mode, maxAllocs int, run func() error, check func(t *testing.T, n int, runErr error))

Sweep runs one of SQLite's two out-of-memory loops.

Rig the allocator to fail once on the N-th allocation for N=1,2,3,....
Repeat until no memory allocations fail.

and the same walk for "fail all allocations beginning with the N-th". The termination condition is what makes it a proof rather than a sample: when a run completes with no allocation refused, N has passed the last allocation the scenario makes, and every allocation failure it can experience has been tried.

run performs the scenario and returns whatever error it produced; a refused allocation is an expected outcome. check runs after every step and holds the invariant — typically that the store is still usable, that nothing was silently dropped, and that nothing panicked.

Types

type Failing

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

Failing refuses allocations according to a mode and a threshold.

func New

func New(mode Mode, nth int) *Failing

New returns an allocator that refuses starting at the nth allocation, counting from 1.

func (*Failing) Bytes

func (f *Failing) Bytes(n int) ([]byte, error)

func (*Failing) Name

func (f *Failing) Name() string

func (*Failing) Seen

func (f *Failing) Seen() int

Seen reports how many requests reached this allocator.

type Mode

type Mode int

Mode selects which of SQLite's two loops an allocator implements.

const (
	// FailOnce refuses the N-th allocation and then behaves normally. It finds
	// handlers that cope with a single failure and then continue.
	FailOnce Mode = iota

	// FailAllFrom refuses the N-th allocation and every one after it. It finds
	// the handlers that only work when a later allocation succeeds — a cleanup
	// path that allocates in order to clean up, for instance.
	FailAllFrom
)

func (Mode) String

func (m Mode) String() string

Jump to

Keyboard shortcuts

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