engine

package
v0.9.5 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2021 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 added in v0.8.0

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

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

type ActionKey added in v0.8.0

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 added in v0.8.0

type ActionOpts map[ActionKey]map[string]string

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

type ActionStats added in v0.8.0

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 added in v0.8.0

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

AverageRuntime returns the average run time for the action.

func (*ActionStats) Record added in v0.8.0

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 added in v0.8.0

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 added in v0.8.0

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 added in v0.8.0

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

New creates an Engine.

func (*Engine) ExecAction added in v0.8.0

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 added in v0.8.0

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

Init initializes the Engine and performs a consistency check.

func (*Engine) RandomAction added in v0.8.0

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 added in v0.8.0

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 added in v0.8.0

func (e *Engine) Stats() string

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

type Log added in v0.8.0

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

Log keeps track of the actions taken by the engine.

func (*Log) AddCompleted added in v0.8.0

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 added in v0.8.0

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

AddEntry adds a LogEntry to the Log.

func (*Log) FindLast added in v0.8.0

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

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

func (*Log) FindLastThisRun added in v0.8.0

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 added in v0.8.0

func (elog *Log) String() string

func (*Log) StringThisRun added in v0.8.0

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 added in v0.8.0

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 added in v0.8.0

func (l *LogEntry) String() string

type Stats added in v0.8.0

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 added in v0.8.0

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