framework

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: 21 Imported by: 0

Documentation

Overview

Package framework contains tools to enable multiple clients to connect to a central repository server and run robustness tests concurrently.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewClientContext

func NewClientContext(ctx context.Context) context.Context

NewClientContext returns a copy of ctx with a new client.

func NewClientContexts

func NewClientContexts(ctx context.Context, n int) []context.Context

NewClientContexts returns copies of ctx with n new clients.

Types

type Client

type Client struct {
	ID string
}

Client is a unique client for use in multiclient robustness tests.

func UnwrapContext

func UnwrapContext(ctx context.Context) *Client

UnwrapContext returns a client from the given context.

type ClientSnapshotter

type ClientSnapshotter interface {
	robustness.Snapshotter
	ConnectClient(fingerprint, user string) error
	DisconnectClient(user string)
	Cleanup()
}

ClientSnapshotter is an interface that wraps robustness.Snapshotter with methods for handling client connections to a server and cleanup.

type FileWriter

type FileWriter interface {
	robustness.FileWriter
	Cleanup()
}

FileWriter is a robustness.FileWriter with the ability to cleanup.

type MultiClientFileWriter

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

MultiClientFileWriter manages a set of client FileWriter instances and implements the FileWriter interface itself. FileWriter methods must be provided with a client-wrapped context so the MultiClientFileWriter can delegate to a specific client FileWriter.

func NewMultiClientFileWriter

func NewMultiClientFileWriter(f newFileWriterFn) *MultiClientFileWriter

NewMultiClientFileWriter returns a MultiClientFileWriter that is responsible for delegating FileWriter method calls to a specific client's FileWriter instance.

func (*MultiClientFileWriter) Cleanup

func (mcfw *MultiClientFileWriter) Cleanup()

Cleanup delegates to a specific client's FileWriter for cleanup and removes the client FileWriter instance from the MultiClientFileWriter.

func (*MultiClientFileWriter) DataDirectory

func (mcfw *MultiClientFileWriter) DataDirectory(ctx context.Context) string

DataDirectory delegates to a specific client's FileWriter.

func (*MultiClientFileWriter) DeleteDirectoryContents

func (mcfw *MultiClientFileWriter) DeleteDirectoryContents(ctx context.Context, opts map[string]string) (map[string]string, error)

DeleteDirectoryContents delegates to a specific client's FileWriter.

func (*MultiClientFileWriter) DeleteEverything

func (mcfw *MultiClientFileWriter) DeleteEverything(ctx context.Context) error

DeleteEverything delegates to a specific client's FileWriter.

func (*MultiClientFileWriter) DeleteRandomSubdirectory

func (mcfw *MultiClientFileWriter) DeleteRandomSubdirectory(ctx context.Context, opts map[string]string) (map[string]string, error)

DeleteRandomSubdirectory delegates to a specific client's FileWriter.

func (*MultiClientFileWriter) WriteRandomFiles

func (mcfw *MultiClientFileWriter) WriteRandomFiles(ctx context.Context, opts map[string]string) (map[string]string, error)

WriteRandomFiles delegates to a specific client's FileWriter.

type MultiClientSnapshotter

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

MultiClientSnapshotter manages a set of client Snapshotter instances and implements the Snapshotter interface itself. Snapshotter methods must be provided with a client-wrapped context so the MultiClientSnapshotter can delegate to a specific client Snapshotter.

func NewMultiClientSnapshotter

func NewMultiClientSnapshotter(baseDirPath string, f newClientFn) (*MultiClientSnapshotter, error)

NewMultiClientSnapshotter returns a MultiClientSnapshotter that is responsible for delegating Snapshotter method calls to a specific client's Snapshotter instance. ConnectOrCreateRepo must be invoked to start the server.

func (*MultiClientSnapshotter) Cleanup

func (mcs *MultiClientSnapshotter) Cleanup()

Cleanup cleans up the server and all remaining clients. It delegates to a specific client's Snapshotter Cleanup method, but also disconnects the client from the server, removes the client from the server's user list, and removes the ClientSnapshotter from MultiClientSnapshotter.

func (*MultiClientSnapshotter) CleanupClient

func (mcs *MultiClientSnapshotter) CleanupClient(ctx context.Context)

CleanupClient cleans up a given client. It delegates to the client's Snapshotter Cleanup method, but also disconnects the client from the server, removes the client from the server's user list, and removes the ClientSnapshotter from MultiClientSnapshotter.

func (*MultiClientSnapshotter) ConnectOrCreateRepo

func (mcs *MultiClientSnapshotter) ConnectOrCreateRepo(repoPath string) error

ConnectOrCreateRepo makes the MultiClientSnapshotter ready for use. It will connect to an existing repository if possible or create a new one, and start a repository server.

func (*MultiClientSnapshotter) CreateSnapshot

func (mcs *MultiClientSnapshotter) CreateSnapshot(ctx context.Context, sourceDir string, opts map[string]string) (snapID string, fingerprint []byte, snapStats *robustness.CreateSnapshotStats, err error)

CreateSnapshot delegates to a specific client's Snapshotter.

func (*MultiClientSnapshotter) DeleteSnapshot

func (mcs *MultiClientSnapshotter) DeleteSnapshot(ctx context.Context, snapID string, opts map[string]string) error

DeleteSnapshot delegates to a specific client's Snapshotter.

func (*MultiClientSnapshotter) ListSnapshots

func (mcs *MultiClientSnapshotter) ListSnapshots(ctx context.Context) ([]string, error)

ListSnapshots delegates to a specific client's Snapshotter.

func (*MultiClientSnapshotter) RestoreSnapshot

func (mcs *MultiClientSnapshotter) RestoreSnapshot(ctx context.Context, snapID, restoreDir string, opts map[string]string) (fingerprint []byte, err error)

RestoreSnapshot delegates to a specific client's Snapshotter.

func (*MultiClientSnapshotter) RestoreSnapshotCompare

func (mcs *MultiClientSnapshotter) RestoreSnapshotCompare(ctx context.Context, snapID, restoreDir string, validationData []byte, reportOut io.Writer, opts map[string]string) (err error)

RestoreSnapshotCompare delegates to a specific client's Snapshotter.

func (*MultiClientSnapshotter) RunGC

func (mcs *MultiClientSnapshotter) RunGC(ctx context.Context, opts map[string]string) error

RunGC runs garbage collection on the server repository directly since clients are not authorized to do this.

func (*MultiClientSnapshotter) ServerCmd

func (mcs *MultiClientSnapshotter) ServerCmd() *exec.Cmd

ServerCmd returns the server command.

type Server

type Server interface {
	// Initialize and cleanup the server
	ConnectOrCreateRepo(repoPath string) error
	Cleanup()

	// Handle client authorization
	AuthorizeClient(user string) error
	RemoveClient(user string)

	// Run commands directly on the server repository
	Run(args ...string) (stdout, stderr string, err error)
	RunGC(ctx context.Context, opts map[string]string) error

	// Get information from the server
	ServerCmd() *exec.Cmd
	ServerFingerprint() string
}

Server is an interface for a repository server.

type TestHarness

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

TestHarness provides a Kopia robustness.Engine.

func NewHarness

func NewHarness(ctx context.Context) *TestHarness

NewHarness returns a test harness. It requires a context that contains a client.

func (*TestHarness) Cleanup

func (th *TestHarness) Cleanup(ctx context.Context) (retErr error)

Cleanup shuts down the engine and stops the test app. It requires a context that contains the client that was used to initialize the harness.

func (*TestHarness) Engine

func (th *TestHarness) Engine() *engine.Engine

Engine returns the Kopia robustness test engine.

func (*TestHarness) Run

func (th *TestHarness) Run(
	ctxs []context.Context,
	t *testing.T, cleanup bool,
	f func(context.Context, *testing.T),
)

Run runs the provided function asynchronously for each of the given client contexts, waits for all of them to finish, and optionally cleans up clients.

func (*TestHarness) RunN

func (th *TestHarness) RunN(
	ctx context.Context,
	t *testing.T,
	numClients int,
	f func(context.Context, *testing.T),
)

RunN creates client contexts, runs the provided function asynchronously for each client, waits for all of them to finish, and cleans up clients.

Jump to

Keyboard shortcuts

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