simio

package
v0.4.6-rc3 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Buggify

func Buggify(probability float64) bool

Buggify returns true with the given probability, but ONLY when simulation mode is active. In production (not enabled), it always returns false with near-zero overhead (single boolean check).

func BuggifyEnabled

func BuggifyEnabled() bool

BuggifyEnabled returns whether simulation fault injection is active.

func DisableBuggify

func DisableBuggify()

DisableBuggify deactivates all fault injection. Call this at the end of a simulation run.

func EnableBuggify

func EnableBuggify(seed int64)

EnableBuggify activates fault injection with the given seed. Call this at the start of a simulation run.

Types

type Clock

type Clock interface {
	Now() time.Time
	After(d time.Duration) <-chan time.Time
	Sleep(d time.Duration)
}

Clock abstracts time operations for deterministic simulation.

type CryptoRand

type CryptoRand struct{}

CryptoRand delegates to crypto/rand (production use).

func (CryptoRand) Read

func (CryptoRand) Read(p []byte) (int, error)

type Env

type Env struct {
	Clock   Clock
	Rand    Rand
	Storage Storage
}

Env bundles all I/O abstractions needed for deterministic simulation. Pass *Env through call chains instead of threading individual interfaces.

func RealEnv

func RealEnv() *Env

RealEnv returns an Env wired to real system I/O (production use).

func SimEnv

func SimEnv(seed int64) *Env

SimEnv returns an Env wired to deterministic implementations controlled by the given seed.

type MemStorage

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

MemStorage is an in-memory Storage implementation for tests and browser fallback.

func NewMemStorage

func NewMemStorage() *MemStorage

NewMemStorage creates a new in-memory storage.

func (*MemStorage) Chtimes

func (m *MemStorage) Chtimes(path string, atime, mtime time.Time) error

Chtimes sets the access and modification times of the named file.

func (*MemStorage) MkdirAll

func (m *MemStorage) MkdirAll(path string, perm os.FileMode) error

MkdirAll creates the directory and all parent directories.

func (*MemStorage) ReadDir

func (m *MemStorage) ReadDir(path string) ([]fs.DirEntry, error)

ReadDir returns directory entries for the given path.

func (*MemStorage) ReadFile

func (m *MemStorage) ReadFile(path string) ([]byte, error)

ReadFile reads the file at the given path. Returns a copy of the data.

func (*MemStorage) Remove

func (m *MemStorage) Remove(path string) error

Remove deletes the file or empty directory at the given path.

func (*MemStorage) Stat

func (m *MemStorage) Stat(path string) (os.FileInfo, error)

Stat returns file info for the given path.

func (*MemStorage) WriteFile

func (m *MemStorage) WriteFile(path string, data []byte, perm os.FileMode) error

WriteFile writes data to the file at the given path. Stores a copy.

type OSStorage

type OSStorage struct{}

OSStorage delegates to the os package. Used in production and WASI.

func (OSStorage) Chtimes

func (OSStorage) Chtimes(path string, atime, mtime time.Time) error

func (OSStorage) MkdirAll

func (OSStorage) MkdirAll(path string, perm os.FileMode) error

func (OSStorage) ReadDir

func (OSStorage) ReadDir(path string) ([]fs.DirEntry, error)

func (OSStorage) ReadFile

func (OSStorage) ReadFile(path string) ([]byte, error)

func (OSStorage) Remove

func (OSStorage) Remove(path string) error

func (OSStorage) Stat

func (OSStorage) Stat(path string) (os.FileInfo, error)

func (OSStorage) WriteFile

func (OSStorage) WriteFile(path string, data []byte, perm os.FileMode) error

type Rand

type Rand interface {
	Read(p []byte) (n int, err error)
}

Rand abstracts random byte generation for deterministic simulation.

type RealClock

type RealClock struct{}

RealClock delegates to the standard time package.

func (RealClock) After

func (RealClock) After(d time.Duration) <-chan time.Time

func (RealClock) Now

func (RealClock) Now() time.Time

func (RealClock) Sleep

func (RealClock) Sleep(d time.Duration)

type SeededRand

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

SeededRand uses a seeded math/rand source for deterministic output.

func NewSeededRand

func NewSeededRand(seed int64) *SeededRand

func (*SeededRand) Read

func (r *SeededRand) Read(p []byte) (int, error)

type SimClock

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

SimClock is a virtual clock for deterministic simulation. Time only advances when Advance or AdvanceTo is called explicitly.

func NewSimClock

func NewSimClock() *SimClock

NewSimClock creates a SimClock starting at Unix epoch zero.

func NewSimClockAt

func NewSimClockAt(t time.Time) *SimClock

NewSimClockAt creates a SimClock starting at the given time.

func (*SimClock) Advance

func (c *SimClock) Advance(d time.Duration)

Advance moves the clock forward by d and fires any expired waiters.

func (*SimClock) AdvanceTo

func (c *SimClock) AdvanceTo(t time.Time)

AdvanceTo sets the clock to t (must be >= current time) and fires any waiters whose deadline has been reached.

func (*SimClock) After

func (c *SimClock) After(d time.Duration) <-chan time.Time

After returns a channel that receives the current time once the clock has been advanced past the deadline. The channel is never selected until Advance/AdvanceTo is called.

func (*SimClock) Now

func (c *SimClock) Now() time.Time

func (*SimClock) PendingCount

func (c *SimClock) PendingCount() int

PendingCount returns the number of waiters that haven't fired yet. Useful for the simulator to know if any node is sleeping.

func (*SimClock) Sleep

func (c *SimClock) Sleep(d time.Duration)

Sleep blocks until the clock has been advanced past now+d. In simulation this is typically called from the simulator driving the clock forward on another goroutine, or within a single-threaded event loop that calls Advance between steps.

type Storage

type Storage interface {
	Stat(path string) (os.FileInfo, error)
	Remove(path string) error
	MkdirAll(path string, perm os.FileMode) error
	ReadFile(path string) ([]byte, error)
	WriteFile(path string, data []byte, perm os.FileMode) error
	ReadDir(path string) ([]fs.DirEntry, error)
	Chtimes(path string, atime, mtime time.Time) error
}

Storage abstracts filesystem operations for WASM portability.

Jump to

Keyboard shortcuts

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