tests

package
v1.13.4-rc.2 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2025 License: BSD-3-Clause Imports: 17 Imported by: 27

Documentation

Index

Constants

View Source
const DefaultTimeout = 2 * time.Minute

A long default timeout used to timeout failed operations but unlikely to induce flaking due to unexpected resource contention.

Variables

This section is empty.

Functions

func ContextWithTimeout added in v1.11.11

func ContextWithTimeout(tc TestContext, duration time.Duration) context.Context

Helper simplifying use of a timed context by canceling the context with the test context.

func DefaultContext added in v1.11.11

func DefaultContext(tc TestContext) context.Context

Helper simplifying use of a timed context configured with the default timeout.

func DefaultNotifyContext added in v1.11.11

func DefaultNotifyContext(duration time.Duration, cleanup func(func())) context.Context

DefaultNotifyContext returns a context that is marked done when signals indicating process termination are received. If a non-zero duration is provided, the parent to the notify context will be a context with a timeout for that duration.

func GetMetricValue added in v1.11.7

func GetMetricValue(metrics NodeMetrics, name string, labels prometheus.Labels) (float64, bool)

GetMetricValue returns the value of the specified metric which has the required labels.

If multiple metrics match the provided labels, the first metric found is returned.

Only Counter and Gauge metrics are supported.

func LoggerForFormat added in v1.12.0

func LoggerForFormat(prefix string, rawLogFormat string) (logging.Logger, error)

TODO(marun) Does/should the logging package have a function like this?

func NewDefaultLogger added in v1.12.0

func NewDefaultLogger(prefix string) logging.Logger

func WithDefaultContext added in v1.11.11

func WithDefaultContext(tc TestContext) common.Option

Helper simplifying use via an option of a timed context configured with the default timeout.

Types

type ErrorfHandler

type ErrorfHandler func(format string, args ...any)

type NodeMetrics added in v1.10.9

type NodeMetrics map[string]*dto.MetricFamily

"metric name" -> "metric value"

func GetNodeMetrics added in v1.10.9

func GetNodeMetrics(ctx context.Context, nodeURI string) (NodeMetrics, error)

GetNodeMetrics retrieves the specified metrics the provided node URI.

type NodesMetrics added in v1.10.9

type NodesMetrics map[string]NodeMetrics

URI -> "metric name" -> "metric value"

func GetNodesMetrics added in v1.10.9

func GetNodesMetrics(ctx context.Context, nodeURIs []string) (NodesMetrics, error)

GetNodesMetrics retrieves the specified metrics for the provided node URIs.

type PanicHandler

type PanicHandler func(any)

type PrometheusServer added in v1.13.3

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

PrometheusServer is a HTTP server that serves Prometheus metrics from the provided gahterer. Listens on localhost with a dynamic port and serves metrics at /ext/metrics.

func NewPrometheusServer added in v1.13.3

func NewPrometheusServer(gatherer prometheus.Gatherer) (*PrometheusServer, error)

NewPrometheusServer creates and starts a Prometheus server with the provided gatherer listening on 127.0.0.1:0 and serving /ext/metrics.

func (*PrometheusServer) Address added in v1.13.3

func (s *PrometheusServer) Address() string

Address returns the address the server is listening on. If the server has not started, the address will be empty.

func (*PrometheusServer) Stop added in v1.13.3

func (s *PrometheusServer) Stop() error

Stop gracefully shuts down the Prometheus server. Waits for the server to shut down and returns any error that occurred during shutdown.

type SimpleTestContext added in v1.11.11

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

func NewTestContext added in v1.11.11

func NewTestContext(log logging.Logger) *SimpleTestContext

func NewTestContextWithArgs

func NewTestContextWithArgs(
	ctx context.Context,
	log logging.Logger,
	errorfHandler ErrorfHandler,
	panicHandler PanicHandler,
) *SimpleTestContext

func (*SimpleTestContext) By added in v1.11.11

func (tc *SimpleTestContext) By(msg string, callback ...func())

func (*SimpleTestContext) ContextWithTimeout added in v1.11.11

func (tc *SimpleTestContext) ContextWithTimeout(duration time.Duration) context.Context

Helper simplifying use of a timed context by canceling the context on ginkgo teardown.

func (*SimpleTestContext) DefaultContext added in v1.11.11

func (tc *SimpleTestContext) DefaultContext() context.Context

Helper simplifying use of a timed context configured with the default timeout.

func (*SimpleTestContext) DeferCleanup added in v1.11.11

func (tc *SimpleTestContext) DeferCleanup(cleanup func())

func (*SimpleTestContext) Errorf added in v1.11.11

func (tc *SimpleTestContext) Errorf(format string, args ...any)

func (*SimpleTestContext) Eventually added in v1.11.11

func (tc *SimpleTestContext) Eventually(condition func() bool, waitFor time.Duration, tick time.Duration, msg string)

func (*SimpleTestContext) FailNow added in v1.11.11

func (*SimpleTestContext) FailNow()

func (*SimpleTestContext) GetDefaultContextParent

func (tc *SimpleTestContext) GetDefaultContextParent() context.Context

func (*SimpleTestContext) Log added in v1.12.0

func (tc *SimpleTestContext) Log() logging.Logger

func (*SimpleTestContext) Recover

func (tc *SimpleTestContext) Recover()

Recover is intended to be deferred in a function executing a test whose assertions may result in panics. Such a panic is intended to be recovered to allow cleanup functions to be called before execution continues.

func (*SimpleTestContext) RecoverAndExit

func (tc *SimpleTestContext) RecoverAndExit()

RecoverAndExit is intended to be deferred by the caller to ensure cleanup functions are called before exit or re-panic (in the event of an unexpected panic or a panic during cleanup).

func (*SimpleTestContext) RecoverAndRethrow

func (tc *SimpleTestContext) RecoverAndRethrow()

RecoverAndRethrow is intended to be deferred in a function executing a test whose assertions may result in panics. Such a panic is intended to be recovered to allow cleanup functions to be called before the panic is rethrown.

func (*SimpleTestContext) SetDefaultContextParent

func (tc *SimpleTestContext) SetDefaultContextParent(parent context.Context)

func (*SimpleTestContext) WithDefaultContext added in v1.11.11

func (tc *SimpleTestContext) WithDefaultContext() common.Option

Helper simplifying use via an option of a timed context configured with the default timeout.

type TestContext added in v1.11.11

type TestContext interface {
	// Ensures the context can be used to instantiate a require instance
	require.TestingT

	// Ensures compatibility with ginkgo.By
	By(text string, callback ...func())

	// Provides a simple alternative to ginkgo.DeferCleanup
	DeferCleanup(cleanup func())

	// Returns a logger that can be used to log test output
	Log() logging.Logger

	// Context helpers requiring cleanup with DeferCleanup
	ContextWithTimeout(duration time.Duration) context.Context
	DefaultContext() context.Context
	WithDefaultContext() common.Option

	// The parent context to use as the parent of default contexts
	GetDefaultContextParent() context.Context

	// Ensures compatibility with require.Eventually
	Eventually(condition func() bool, waitFor time.Duration, tick time.Duration, msg string)
}

Directories

Path Synopsis
avalanchego command
xsvm command
e2e
banff
Implements tests for the banff network upgrade.
Implements tests for the banff network upgrade.
c
p
vms
x
x/transfer
Implements X-chain transfer tests.
Implements X-chain transfer tests.
fixture
e2e
main command

Jump to

Keyboard shortcuts

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