tests

package
v4.0.0-...-699247e Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package tests implements a testing framwork, and provides default tests.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoTests returns no test params are set.
	ErrNoTests = errors.New("No tests to run, all values set to 0")
)

Functions

func RunBenchmark

func RunBenchmark(b *testing.B, name string, service micro.Service, test testFunc,
	cancel context.CancelFunc, started chan struct{})

RunBenchmark will run benchmarks on a provided service.

A test function can be provided that will be fun b.N times.

Types

type ServiceTestConfig

type ServiceTestConfig struct {
	// Service name to use for the tests
	Name string
	// NewService function will be called to setup the new service.
	// It takes in a list of options, which by default will Context and an
	// AfterStart with channel to signal when the service has been started.
	NewService func(name string, opts ...micro.Option) (micro.Service, error)
	// Parallel is the number of prallell routines to use for the tests.
	Parallel []int
	// Sequential is the number of sequential requests to send per parallel process.
	Sequential []int
	// Streams is the nummber of streaming messages to send over the stream per routine.
	Streams []int
	// PubSub is the number of times to publish messages to the broker per routine.
	PubSub []int
	// contains filtered or unexported fields
}

ServiceTestConfig allows you to easily test a service configuration by running predefined tests against your custom service. You only need to provide a function to create the service, and how many of which test you want to run.

The default tests provided, all running with separate parallel routines are:

  • Sequential Call requests
  • Bi-directional streaming
  • Pub/Sub events brokering

You can provide an array of parallel routines to run for the request and stream tests. They will be run as matrix tests, so with each possible combination. Thus, in total (p * seq) + (p * streams) tests will be run.

func (*ServiceTestConfig) Handle

func (stc *ServiceTestConfig) Handle(ctx context.Context, msg *proto.Request) error

Handle is used as a test handler.

func (*ServiceTestConfig) HandleError

func (stc *ServiceTestConfig) HandleError(ctx context.Context, msg *proto.Request) error

HandleError is used as a test handler.

func (*ServiceTestConfig) Run

func (stc *ServiceTestConfig) Run(b *testing.B)

Run will start the benchmark tests.

Jump to

Keyboard shortcuts

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