suite

package
v3.2.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2016 License: BSD-3-Clause Imports: 27 Imported by: 0

Documentation

Overview

Package suite contains functions to input tests from disk and execute suites of tests in a controlled way.

Variable Handling

There are three "scopes" for variables when executing a suite read from disk (a RawSuite):

  • Global Scope: Variables set from "the outside", typically via the -D command line flag to cmd/ht. Executing a suite or tests does not modify variables in this scope. This global set of varibales is input to the Execute method of RawSuite.

  • Suite Scope: This is the context of the suite, it can be changed dynamically via variable extraction from executed tests. The initial suite scope is:

  • a copy of the Global Scope, with

  • added COUNTER and RANDOM variables and

  • merged defaults from the suite's Variables section. Variable expansion happens inside the values of the Variables section.

  • Test Scope: The tests scope is the context of a test, actually the set of variables used to make a ht.Test from a RawTest. It is constructed as follows:

  • To a copy of the actual suite scope,

  • the automatic variables COUNTER and RANDOM are added (with new values),

  • merged with the call Variables

  • merged with the tests Variables section. Variable expansion happens inside the values of the call and test Variables section.

Here "merging" means that the variables in the Variables section are added to the scope if not already present. I.e. the variables from outer scope dominate variables from inner scopes.

Throughput Load-Testing

Load tests in the form of a throuhghput-test can be made through the Throughput function. This function will try to create a certain throughput load, i.e. a certain average number of request per second. The intervalls between request follow an exponential distribution which mimics the load generated from real-world, uncorrelated users.

The requests are generated from different Scenarios which contribute a certain percentage of requests to the set of all requests. The scenarios are basically just suites of tests: One suite might simulate the bahaviour of a bot while an other scenario can simulate the behaviour of a "normal" user and a third scenario performs actions a user with special interests.

The Tests of each suite/scenario are executed, including the checks. Note that some checks can produce additional requests which are not accounted in the throughput rate of the load test (but do hit the target server). Checks can be turned off on per scenario basis.

If all tests (and thus request) in a suite/scenario have been executed, the suite is repeated. To reach the desired request througput rate each scenario is run in multiple parallel threads. New threads are started as needed. The number of threads may be limited on a per scenario basis.

Index

Constants

This section is empty.

Variables

View Source
var (
	SuiteTmpl      *template.Template
	ShortSuiteTmpl *template.Template
	HtmlSuiteTmpl  *htmltemplate.Template
)
View Source
var (
	ErrAbortExecution = errors.New("Abort Execution")
)
View Source
var GetCounter <-chan int

GetCounter returns a strictly increasing sequence of int values.

View Source
var IDSep = "\u2237"

IDSep is the separator string used in constructing IDs for the individual test executed. The test Name are (miss)used to report details:

<ScenarioNo>/<ThreadNo>/<Repetition>/<TestNo> IDSep <ScenarioName> IDSep <TestName>

Functions

func DataPrint

func DataPrint(data []bender.TestData, out io.Writer)

DataPrint prints data to out in human readable tabular format.

func DataToCSV

func DataToCSV(data []bender.TestData, out io.Writer) error

DataToCSV prints data as a CVS table to out after sorting data by Started.

func HTMLReport

func HTMLReport(dir string, s *Suite) error

HTMLReport generates a report of the outcome of s to directory dir.

Types

type Executor

type Executor func(test *ht.Test) error

A Executor is responsible for executing the given test during the Iterate'ion of a Suite. It should return nil if execution should continue and ErrAbortExecution to stop further iteration.

type File

type File struct {
	Data string
	Name string
}

File is a textual representation of a hjson data read from disk.

func LoadFile

func LoadFile(filename string) (*File, error)

LoadFile reads the given file and returns it as a File.

func (*File) Basename

func (f *File) Basename() string

Basename of f.

func (*File) Dirname

func (f *File) Dirname() string

Dirname of f.

type FileSystem

type FileSystem map[string]*File

FileSystem acts like an in-memory filesystem. A empty FileSystem accesses the real OS file system.

func NewFileSystem

func NewFileSystem(txt string) (FileSystem, error)

NewFileSystem parses txt which must be of the form

# <filename1>
<filecontent1>

# <filename2>
<filecontent2>

...

into a new FileSystem.

func (FileSystem) Load

func (fs FileSystem) Load(name string) (*File, error)

type LoopIteration

type LoopIteration struct {
	Data      interface{}
	I         int // 0-based loop index
	N         int // 1-based loop index
	Odd, Even bool
}

LoopIteration helps ranging over Data in a template.

type Mixin

type Mixin struct {
	*File
}

Mixin of a test.

type RawElement

type RawElement struct {
	File      string
	Variables map[string]string

	Test map[string]interface{}
}

RawElement represents one test in a RawSuite.

type RawLoadTest

type RawLoadTest struct {
	*File
	Name        string
	Description string
	Scenarios   []RawScenario
	Variables   map[string]string
}

RawLoadTest as read from disk.

func LoadRawLoadtest

func LoadRawLoadtest(filename string, fs FileSystem) (*RawLoadTest, error)

LoadRawLoadtest from the given filename.

func (*RawLoadTest) ToScenario

func (raw *RawLoadTest) ToScenario(globals map[string]string) []Scenario

ToScenario produces a list of scenarios from raw.

type RawScenario

type RawScenario struct {
	Name       string            // Name of this Scenario
	File       string            // File is the RawSuite to use as scenario
	Percentage int               // Percantage this scenario contributes to the load test.
	MaxThreads int               // MaxThreads to use for this scenario. 0 means unlimited.
	Variables  map[string]string // Variables used.
	OmitChecks bool              // OmitChecks in the tests.
	// contains filtered or unexported fields
}

RawScenario represents a scenario in a load test.

type RawSuite

type RawSuite struct {
	*File
	Name, Description     string
	Setup, Main, Teardown []RawElement
	KeepCookies           bool
	OmitChecks            bool
	Variables             map[string]string
	Verbosity             int
	// contains filtered or unexported fields
}

RawSuite represents a suite as represented on disk as a HJSON file.

func LoadRawSuite

func LoadRawSuite(filename string, fs FileSystem) (*RawSuite, error)

LoadRawSuite with the given filename from fs.

func (*RawSuite) AddRawTests

func (rs *RawSuite) AddRawTests(ts ...*RawTest)

AddRawTest adds ts to the tests in rs.

func (*RawSuite) Execute

func (rs *RawSuite) Execute(global map[string]string, jar *cookiejar.Jar, logger *log.Logger) *Suite

Execute the raw suite rs and capture the outcome in a Suite.

Tests are executed linearely, first the Setup, then the Main and finaly the Teardown test. Any Failure or error during setup will skip further setup and main test (but allteardown will be executed). The following table shows two runs with possible outcomes.

  Test Type     Run1     Run2
------------------------------------------
  Setup-1       Pass     Pass
  Setup-2       Fail     Pass
  Setup-3       Skip     Pass
  Main-1        Skip     Fail
  Main-2        Skip     Pass
  Teardown-1    Pass     Pass
  Teardown-2    Fail     Error
  Teardown-3    Pass     Pass

func (*RawSuite) RawTests

func (rs *RawSuite) RawTests() []*RawTest

RawTests return all tests in rs.

func (*RawSuite) Validate

func (rs *RawSuite) Validate(global map[string]string) error

Validate rs to make sure it can be decoded into welformed ht.Tests.

type RawTest

type RawTest struct {
	*File
	Mixins    []*Mixin          // Mixins of this test.
	Variables map[string]string // Variables are the defaults of the variables.
	// contains filtered or unexported fields
}

RawTest is a raw for of a test as read from disk with its mixins and its variables.

func LoadRawTest

func LoadRawTest(filename string, fs FileSystem) (*RawTest, error)

LoadRawTest reads filename and produces a new RawTest.

func (*RawTest) Disable

func (rt *RawTest) Disable()

Disable rt.

func (*RawTest) Enable

func (rt *RawTest) Enable()

Enable rt.

func (*RawTest) IsEnabled

func (rt *RawTest) IsEnabled() bool

IsEnabled reports if rt is enabled.

func (*RawTest) String

func (rt *RawTest) String() string

func (*RawTest) ToTest

func (rt *RawTest) ToTest(variables map[string]string) (*ht.Test, error)

ToTest produces a ht.Test from a raw test rt.

type Scenario

type Scenario struct {
	// Name of this scenario. May differ from the suite.
	Name string

	// RawSuite is the suite to execute repeatedly to generate load.
	*RawSuite

	// Percentage of requests in the throughput test taken from this
	// scenario.
	Percentage int

	// MaxThreads limits the number of threads used to generate load from
	// this scenario. The value 0 indicates unlimited number of threads.
	MaxThreads int

	// OmitChecks turns off checks in this scenario, i.e. only the request
	// is made but no checks are performed on the response.
	OmitChecks bool

	// The logger to use for tests of this scenario.
	Log *log.Logger
	// contains filtered or unexported fields
}

Scenario describes a single scenario to be run as part of a throughput test.

type Suite

type Suite struct {
	Name        string // Name of the Suite.
	Description string // Description of what's going on here.
	KeepCookies bool   // KeepCookies in a cookie jar common to all Tests.

	Status   ht.Status     // Status is the overall status of the whole suite.
	Error    error         // Error encountered during execution of the suite.
	Started  time.Time     // Start of the execution.
	Duration time.Duration // Duration of the execution.

	Tests []*ht.Test // The Tests to execute

	Variables      map[string]string // The initial variable assignemnt
	FinalVariables map[string]string // The final set of variables.
	Jar            *cookiejar.Jar    // The cookie jar used
	Log            *log.Logger       // The logger used.
	// contains filtered or unexported fields
}

A Suite is a collection of Tests which can be executed sequentily with the result captured.

func NewFromRaw

func NewFromRaw(rs *RawSuite, global map[string]string, jar *cookiejar.Jar, logger *log.Logger) *Suite

NewFromRaw sets up a new Suite from rs, read to be Iterated.

func Throughput

func Throughput(scenarios []Scenario, rate float64, duration, ramp time.Duration) ([]bender.TestData, *Suite, error)

Throughput runs a throughput load test with an average rate of request/seconds for the given duration. The request are generated from the given scenarios. It returns a summary of all request, all failed tests collected into a Suite and an error indicating if the throughput test reached the targeted rate and distribution.

func (*Suite) Iterate

func (suite *Suite) Iterate(executor Executor)

Iterate the suite through the given executor.

func (*Suite) JUnit4XML

func (s *Suite) JUnit4XML() (string, error)

JUnit4XML generates a JUnit 4 compatible XML result with each Check reported as an individual testcase. NotRun checks are reported as Skipped and Bogus checks are counted as Errored tests.

func (*Suite) PrintReport

func (s *Suite) PrintReport(w io.Writer) error

PrintReport outputs a textual report of s to w.

func (*Suite) PrintShortReport

func (s *Suite) PrintShortReport(w io.Writer) error

PrintShortReport outputs a short textual report of s to w.

func (*Suite) Stats

func (suite *Suite) Stats() (notRun int, skipped int, passed int, failed int, errored int, bogus int)

Stats counts the test results of s.

Jump to

Keyboard shortcuts

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