engine

package
v0.0.0-...-58c64f7 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2025 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package engine provides the framework for a snapshot repository testing engine

Index

Constants

View Source
const (
	ActionRepeaterField          = "repeat-action"
	ThrowNoSpaceOnDeviceErrField = "throw-no-space-error"
	SnapshotIDField              = "snapshot-ID"
	SubPathOptionName            = "sub-path"
)

Option field names.

Variables

View Source
var (
	// ErrInvalidArgs is returned if the constructor arguments are incorrect.
	ErrInvalidArgs = fmt.Errorf("invalid arguments")
)

Functions

This section is empty.

Types

type Action

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

Action is a unit of functionality that can be executed by the engine.

type ActionKey

type ActionKey string

ActionKey refers to an action that can be executed by the engine.

const (
	ActionControlActionKey            ActionKey = "action-control"
	SnapshotDirActionKey              ActionKey = "snapshot-root"
	RestoreSnapshotActionKey          ActionKey = "restore-random-snapID"
	DeleteRandomSnapshotActionKey     ActionKey = "delete-random-snapID"
	WriteRandomFilesActionKey         ActionKey = "write-random-files"
	DeleteRandomSubdirectoryActionKey ActionKey = "delete-random-subdirectory"
	DeleteDirectoryContentsActionKey  ActionKey = "delete-files"
	RestoreIntoDataDirectoryActionKey ActionKey = "restore-into-data-dir"
	GCActionKey                       ActionKey = "run-gc"
)

List of action keys.

type ActionOpts

type ActionOpts map[ActionKey]map[string]string

ActionOpts is a structure that designates the options for picking and running an action.

type ActionStats

type ActionStats struct {
	Count        int64
	TotalRuntime time.Duration
	MinRuntime   time.Duration
	MaxRuntime   time.Duration
	ErrorCount   int64
}

ActionStats tracks runtime statistics for an action.

func (*ActionStats) AverageRuntime

func (s *ActionStats) AverageRuntime() time.Duration

AverageRuntime returns the average run time for the action.

func (*ActionStats) Record

func (s *ActionStats) Record(st time.Time, err error)

Record records the current time against the provided start time and updates the stats accordingly.

type Args

type Args struct {
	// Interfaces used by the engine.
	MetaStore  robustness.Persister
	TestRepo   robustness.Snapshotter
	FileWriter robustness.FileWriter

	// WorkingDir is a directory to use for temporary data.
	WorkingDir string

	// SyncRepositories should be set to true to reconcile differences.
	SyncRepositories bool
}

Args contain the parameters for the engine constructor.

func (*Args) Validate

func (a *Args) Validate() error

Validate checks the arguments for correctness.

type Engine

type Engine struct {
	FileWriter robustness.FileWriter
	TestRepo   robustness.Snapshotter
	MetaStore  robustness.Persister

	Checker *checker.Checker

	RunStats        Stats
	CumulativeStats Stats

	EngineLog Log
	// contains filtered or unexported fields
}

Engine is the outer level testing framework for robustness testing.

func New

func New(args *Args) (*Engine, error)

New creates an Engine.

func (*Engine) CheckErrRecovery

func (e *Engine) CheckErrRecovery(ctx context.Context, incomingErr error, actionOpts ActionOpts) (outgoingErr error)

CheckErrRecovery tries to recover from no space left error by deleting data directories.

func (*Engine) ExecAction

func (e *Engine) ExecAction(ctx context.Context, actionKey ActionKey, opts map[string]string) (map[string]string, error)

ExecAction executes the action denoted by the provided ActionKey.

func (*Engine) Init

func (e *Engine) Init(ctx context.Context) error

Init initializes the Engine and performs a consistency check.

func (*Engine) RandomAction

func (e *Engine) RandomAction(ctx context.Context, actionOpts ActionOpts) error

RandomAction executes a random action picked by the relative weights given in actionOpts[ActionControlActionKey], or uniform probability if that key is not present in the input options.

func (*Engine) Shutdown

func (e *Engine) Shutdown(ctx context.Context) error

Shutdown makes a last snapshot then flushes the metadata and prints the final statistics.

func (*Engine) Stats

func (e *Engine) Stats() string

Stats prints the engine stats, cumulative and from the current run.

type Log

type Log struct {
	Log []*LogEntry
	// contains filtered or unexported fields
}

Log keeps track of the actions taken by the engine.

func (*Log) AddCompleted

func (elog *Log) AddCompleted(logEntry *LogEntry, err error)

AddCompleted finalizes a log entry at the time it is called and with the provided error, before adding it to the Log.

func (*Log) AddEntry

func (elog *Log) AddEntry(l *LogEntry)

AddEntry adds a LogEntry to the Log.

func (*Log) FindLast

func (elog *Log) FindLast(actionKey ActionKey) *LogEntry

FindLast finds the most recent log entry with the provided ActionKey.

func (*Log) FindLastThisRun

func (elog *Log) FindLastThisRun(actionKey ActionKey) (found *LogEntry)

FindLastThisRun finds the most recent log entry with the provided ActionKey, limited to the current run only.

func (*Log) String

func (elog *Log) String() string

func (*Log) StringThisRun

func (elog *Log) StringThisRun() string

StringThisRun returns a string of only the log entries generated by actions in this run of the engine.

type LogEntry

type LogEntry struct {
	StartTime       time.Time
	EndTime         time.Time
	EngineTimestamp int64
	Action          ActionKey
	Error           string
	Idx             int64
	ActionOpts      map[string]string
	CmdOpts         map[string]string
}

LogEntry is an entry for the engine log.

func (*LogEntry) String

func (l *LogEntry) String() string

type Stats

type Stats struct {
	RunCounter     int64
	ActionCounter  int64
	CreationTime   time.Time
	RunTime        time.Duration
	PerActionStats map[ActionKey]*ActionStats

	DataRestoreCount   int64
	DataPurgeCount     int64
	ErrorRecoveryCount int64
	NoOpCount          int64
}

Stats tracks statistics during engine runtime.

func (*Stats) Stats

func (stats *Stats) Stats() string

Stats returns a string report of the engine's stats.

Jump to

Keyboard shortcuts

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