testbed

package
v0.0.0-...-e87131c Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2019 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Overview

Package testbed allows to easily set up a test that requires running the agent and a load generator, measure and define resource consumption expectations for the agent, fail tests automatically when expectations are exceeded.

Each test case requires a agent configuration file and (optionally) load generator spec file. Test cases are defined as regular Go tests.

Agent and load generator must be pre-built and their paths must be specified in test bed config file. The config file location must be provided in TESTBED_CONFIG env variable.

Index

Constants

This section is empty.

Variables

View Source
var ErrSkipTests = errors.New("skip tests")

ErrSkipTests indicates that the tests must be skipped.

Functions

func LoadConfig

func LoadConfig() error

LoadConfig loads test bed config.

func SaveResults

func SaveResults()

func Start

func Start() error

Types

type BackendType

type BackendType int
const (
	BackendJaeger BackendType = iota
	BackendOC
)

type GlobalConfig

type GlobalConfig struct {
	Agent         string
	LoadGenerator string `mapstructure:"load-generator"`
}

GlobalConfig defines test bed configuration.

type LoadGenerator

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

LoadGenerator is a simple load generator.

func NewLoadGenerator

func NewLoadGenerator() (*LoadGenerator, error)

NewLoadGenerator creates a load generator.

func (*LoadGenerator) GetStats

func (lg *LoadGenerator) GetStats() string

GetStats returns the stats as a printable string.

func (*LoadGenerator) SpansSent

func (lg *LoadGenerator) SpansSent() uint64

func (*LoadGenerator) Start

func (lg *LoadGenerator) Start(options LoadOptions)

Start the load.

func (*LoadGenerator) Stop

func (lg *LoadGenerator) Stop()

Stop the load.

type LoadOptions

type LoadOptions struct {
	// SpansPerSecond specifies how many spans to generate each second.
	SpansPerSecond uint

	// SpansPerTrace specifies how many spans per trace to generate. Should be equal or greater than zero.
	// The number of traces generated per second will be SpansPerSecond/SpansPerTrace.
	SpansPerTrace uint

	// Attributes to add to each generated span. Can be empty.
	Attributes map[string]interface{}
}

LoadOptions defines the options to use for generating the load.

type MockBackend

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

MockBackend is a backend that allows receiving the data locally.

func NewMockBackend

func NewMockBackend(logFilePath string) *MockBackend

NewMockBackend creates a new mock backend.

func (*MockBackend) Context

func (mb *MockBackend) Context() context.Context

func (*MockBackend) GetStats

func (mb *MockBackend) GetStats() string

func (*MockBackend) OkToIngest

func (mb *MockBackend) OkToIngest() bool

func (*MockBackend) ReportFatalError

func (mb *MockBackend) ReportFatalError(err error)

func (*MockBackend) SpansReceived

func (mb *MockBackend) SpansReceived() uint64

func (*MockBackend) Start

func (mb *MockBackend) Start(backendType BackendType) error

Start a backend of specified type. Only one backend type can be started at a time.

func (*MockBackend) Stop

func (mb *MockBackend) Stop()

Stop the backend

type ResourceConsumption

type ResourceConsumption struct {
	CPUPercentAvg float64
	CPUPercentMax float64
	RAMMiBAvg     uint32
	RAMMiBMax     uint32
}

type Results

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

func (*Results) Add

func (r *Results) Add(testName string, result *TestResult)

Add results for one test.

func (*Results) Init

func (r *Results) Init(resultsDir string)

func (*Results) Save

func (r *Results) Save()

Save the total results and close the file.

type TestCase

type TestCase struct {
	LoadGenerator *LoadGenerator
	MockBackend   *MockBackend

	// ErrorSignal indicates an error in the test case execution, e.g. process execution
	// failure or exceeding resource consumption, etc. The actual error message is already
	// logged, this is only an indicator on which you can wait to be informed.
	ErrorSignal chan struct{}
	// contains filtered or unexported fields
}

TestCase defines a running test case.

func NewTestCase

func NewTestCase(t *testing.T, opts ...TestCaseOption) *TestCase

NewTestCase creates a new TestCase. It expected agent-config.yaml in the specified directory.

func (*TestCase) AgentMemoryInfo

func (tc *TestCase) AgentMemoryInfo() (uint32, uint32, error)

AgentMemoryInfo returns raw memory info struct about the agent as returned by github.com/shirou/gopsutil/process

func (*TestCase) SetExpectedMaxCPU

func (tc *TestCase) SetExpectedMaxCPU(cpuPercentage uint32)

SetExpectedMaxCPU sets the percentage of one core agent is expected to consume at most. Error is signalled if consumption during resourceCheckPeriod exceeds this number. If this function is not called the CPU consumption does not affect the test result.

func (*TestCase) SetExpectedMaxRAM

func (tc *TestCase) SetExpectedMaxRAM(ramMiB uint32)

SetExpectedMaxRAM sets the maximum RAM in MiB the agent is expected to consume. Error is signalled if consumption during resourceCheckPeriod exceeds this number. If this function is not called the RAM consumption does not affect the test result.

func (*TestCase) Sleep

func (tc *TestCase) Sleep(d time.Duration)

Sleep for specified duration or until error is signalled.

func (*TestCase) StartAgent

func (tc *TestCase) StartAgent(args ...string)

StartAgent starts the agent and redirects its standard output and standard error to "agent.log" file located in the test directory.

func (*TestCase) StartBackend

func (tc *TestCase) StartBackend(backendType BackendType)

StartBackend starts the specified backend type.

func (*TestCase) StartLoad

func (tc *TestCase) StartLoad(options LoadOptions)

StartLoad starts the load generator and redirects its standard output and standard error to "load-generator.log" file located in the test directory.

func (*TestCase) Stop

func (tc *TestCase) Stop()

Stop stops the load generator, the agent and the backend.

func (*TestCase) StopAgent

func (tc *TestCase) StopAgent()

StopAgent stops agent process.

func (*TestCase) StopBackend

func (tc *TestCase) StopBackend()

StopBackend stops the backend.

func (*TestCase) StopLoad

func (tc *TestCase) StopLoad()

StopLoad stops load generator.

func (*TestCase) ValidateData

func (tc *TestCase) ValidateData()

ValidateData validates data by comparing the number of spans sent by load generator and number of spans received by mock backend.

func (*TestCase) WaitFor

func (tc *TestCase) WaitFor(cond func() bool, errMsg ...interface{}) bool

WaitFor is like WaitForN but with a fixed duration of 10 seconds

func (*TestCase) WaitForN

func (tc *TestCase) WaitForN(cond func() bool, duration time.Duration, errMsg ...interface{}) bool

WaitForN the specific condition for up to a specified duration. Records a test error if time is out and condition does not become true. If error is signalled while waiting the function will return false, but will not record additional test error (we assume that signalled error is already recorded in indicateError()).

type TestCaseOption

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

TestCaseOption defines a TestCase option.

func WithConfigFile

func WithConfigFile(file string) TestCaseOption

WithConfigFile allows a custom configuration file for TestCase.

func WithSkipResults

func WithSkipResults() TestCaseOption

WithSkipResults option disables writing out results file for a TestCase.

func (TestCaseOption) Apply

func (o TestCaseOption) Apply(t *TestCase)

Apply takes a TestCase and runs the option function on it.

type TestResult

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

Jump to

Keyboard shortcuts

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