event

package
v0.0.0-...-deba56b Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2023 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package event contains the event system used to notify external components of various internal events during test execution.

Index

Constants

This section is empty.

Variables

View Source
var (
	// GlobalEvents are emitted once per test run.
	GlobalEvents = []Type{Init, TestStart, TestEnd, Exit}
	// VUEvents are emitted multiple times per each VU.
	VUEvents = []Type{IterStart, IterEnd}
)

Functions

This section is empty.

Types

type Event

type Event struct {
	Type Type
	Data any
	Done func()
}

Event is the emitted object sent to all subscribers of its type. The subscriber should call its Done method when finished processing to notify the emitter, though this is not required for all events.

type ExitData

type ExitData struct {
	Error error
}

ExitData is the data sent in the Exit event. Error is the error returned by the run command.

type IterData

type IterData struct {
	Iteration    int64
	VUID         uint64
	ScenarioName string
	Error        error
}

IterData is the data sent in the IterStart and IterEnd events.

type Subscriber

type Subscriber interface {
	Subscribe(events ...Type) (subID uint64, eventsCh <-chan *Event)
	Unsubscribe(subID uint64)
}

Subscriber is a limited interface of System that only allows subscribing and unsubscribing.

type System

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

System keeps track of subscribers, and allows subscribing to and emitting events.

func NewEventSystem

func NewEventSystem(eventBuffer int, logger logrus.FieldLogger) *System

NewEventSystem returns a new System. eventBuffer determines the size of the Event channel buffer. Events might be dropped if this buffer is full and there are no event listeners, or if events are emitted very quickly and the event handler goroutine is busy. It is recommended to handle events in a separate goroutine to not block the listener goroutine.

func (*System) Emit

func (s *System) Emit(event *Event) (wait func(context.Context) error)

Emit the event to all subscribers of its type. It returns a function that can be optionally used to wait for all subscribers to process the event (by signalling via the Done method).

func (*System) Subscribe

func (s *System) Subscribe(events ...Type) (subID uint64, eventsCh <-chan *Event)

Subscribe to one or more events. It returns a subscriber ID that can be used to unsubscribe, and an Event channel to receive events. It panics if events is empty.

func (*System) Unsubscribe

func (s *System) Unsubscribe(subID uint64)

Unsubscribe closes the Event channel and removes the subscription with ID subID.

func (*System) UnsubscribeAll

func (s *System) UnsubscribeAll()

UnsubscribeAll closes all event channels and removes all subscriptions.

type Type

type Type uint8

Type represents the different event types emitted by k6.

const (
	// Init is emitted when k6 starts initializing outputs, VUs and executors.
	Init Type = iota + 1
	// TestStart is emitted when the execution scheduler starts running the test.
	TestStart
	// TestEnd is emitted when the test execution ends.
	TestEnd
	// IterStart is emitted when a VU starts an iteration.
	IterStart
	// IterEnd is emitted when a VU ends an iteration.
	IterEnd
	// Exit is emitted when the k6 process is about to exit.
	Exit
)

func TypeString

func TypeString(s string) (Type, error)

TypeString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.

func TypeValues

func TypeValues() []Type

TypeValues returns all values of the enum

func (Type) IsAType

func (i Type) IsAType() bool

IsAType returns "true" if the value is listed in the enum definition. "false" otherwise

func (Type) String

func (i Type) String() string

Jump to

Keyboard shortcuts

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