test

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2025 License: Apache-2.0 Imports: 36 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckMetrics

func CheckMetrics(t *testing.T, url string, expectedMetrics ...string)

CheckMetrics checks the metrics endpoint for the expected metrics.

func CheckServerStopped

func CheckServerStopped(t *testing.T, addr string) bool

CheckServerStopped returns true if the grpc server listening on a given address has been stopped.

func EnsurePersistedTxStatus

func EnsurePersistedTxStatus(
	ctx context.Context,
	t *testing.T,
	r StatusRetriever,
	txIDs []string,
	expected map[string]*protoblocktx.StatusWithHeight,
)

EnsurePersistedTxStatus fails the test if the given TX IDs does not match the expected status.

func EventuallyIntMetric

func EventuallyIntMetric(
	t *testing.T, expected int, m prometheus.Metric, waitFor, tick time.Duration, msgAndArgs ...any,
)

EventuallyIntMetric fail the test if the integer metric is not equal to the expected value after the given duration.

func FailHandler

func FailHandler(t *testing.T)

FailHandler registers a gomega fail handler.

func GetIntMetricValue

func GetIntMetricValue(t *testing.T, m prometheus.Metric) int

GetIntMetricValue returns the value of a prometheus metric, rounded to the nearest integer.

func GetMetricValue

func GetMetricValue(t *testing.T, m prometheus.Metric) float64

GetMetricValue returns the value of a prometheus metric.

func GetMetricValueFromURL

func GetMetricValueFromURL(t *testing.T, url, metricName string) int

GetMetricValueFromURL reads the metrics endpoint and fetch the value of a specific metric.

func LogStruct added in v0.1.6

func LogStruct(t *testing.T, name string, v any)

LogStruct logs a struct in a flat representation.

func RequireIntMetricValue

func RequireIntMetricValue(t *testing.T, expected int, m prometheus.Metric)

RequireIntMetricValue fail the test if the integer metric is not equal to the expected value.

func RequireProtoElementsMatch

func RequireProtoElementsMatch[T proto.Message](
	t require.TestingT, expected, actual []T, msgAndArgs ...any,
)

RequireProtoElementsMatch verifies that two arrays of proto have the same elements.

func RequireProtoEqual

func RequireProtoEqual(t require.TestingT, expected, actual proto.Message)

RequireProtoEqual verifies that two proto are equal.

func RunGrpcServerForTest

func RunGrpcServerForTest(
	ctx context.Context, tb testing.TB, serverConfig *connection.ServerConfig, register func(server *grpc.Server),
) *grpc.Server

RunGrpcServerForTest starts a GRPC server using a register method. It handles the cleanup of the GRPC server at the end of a test, and ensure the test is ended only when the GRPC server is down. It also updates the server config endpoint port to the actual port if the configuration did not specify a port. The method asserts that the GRPC server did not end with failure.

func RunServiceAndGrpcForTest

func RunServiceAndGrpcForTest(
	ctx context.Context,
	t *testing.T,
	service connection.Service,
	serverConfig ...*connection.ServerConfig,
) *channel.Ready

RunServiceAndGrpcForTest combines running a service and its GRPC server. It is intended for services that implements the Service API (i.e., command line services).

func RunServiceForTest

func RunServiceForTest(
	ctx context.Context,
	tb testing.TB,
	service func(ctx context.Context) error,
	waitFunc func(ctx context.Context) bool,
) *channel.Ready

RunServiceForTest runs a service using the given service method, and waits for it to be ready given the waitFunc method. It handles the cleanup of the service at the end of a test, and ensure the test is ended only when the service return. The method asserts that the service did not end with failure. Returns a ready flag that indicate that the service is done.

func ServerToClientConfig

func ServerToClientConfig(servers ...*connection.ServerConfig) *connection.ClientConfig

ServerToClientConfig is used to create client configuration from existing server(s).

func SetupDebugging

func SetupDebugging()

SetupDebugging can be added for development to tests that required additional debugging info.

func WaitUntilGrpcServerIsDown added in v0.1.6

func WaitUntilGrpcServerIsDown(
	ctx context.Context,
	t *testing.T,
	conn grpc.ClientConnInterface,
)

WaitUntilGrpcServerIsDown uses the health check API to check a service is down.

func WaitUntilGrpcServerIsReady

func WaitUntilGrpcServerIsReady(
	ctx context.Context,
	t *testing.T,
	conn grpc.ClientConnInterface,
)

WaitUntilGrpcServerIsReady uses the health check API to check a service readiness.

Types

type BroadcastStream added in v0.1.6

type BroadcastStream struct {
	Broadcaster
	ConnectionManager *ordererconn.ConnectionManager
}

BroadcastStream implements broadcast, with the addition of automatically signing the envelope.

func NewBroadcastStream added in v0.1.6

func NewBroadcastStream(ctx context.Context, config *ordererconn.Config) (*BroadcastStream, error)

NewBroadcastStream starts a new broadcast stream (non-production).

func (*BroadcastStream) Close added in v0.1.6

func (s *BroadcastStream) Close()

Close closes all the connections for the stream.

func (*BroadcastStream) SendBatch added in v0.1.6

func (s *BroadcastStream) SendBatch(envelopes []*common.Envelope) error

SendBatch sends a batch one by one.

type Broadcaster added in v0.1.6

type Broadcaster interface {
	Send(*common.Envelope) error
}

Broadcaster can be either CFT or BFT broadcast.

type GrpcServers

type GrpcServers struct {
	Servers []*grpc.Server
	Configs []*connection.ServerConfig
}

GrpcServers holds the server instances and their respective configurations.

func StartGrpcServersForTest

func StartGrpcServersForTest(
	ctx context.Context,
	t *testing.T,
	numService int,
	register func(*grpc.Server, int),
) *GrpcServers

StartGrpcServersForTest starts multiple GRPC servers with a default configuration.

func StartGrpcServersWithConfigForTest

func StartGrpcServersWithConfigForTest(
	ctx context.Context, t *testing.T, sc []*connection.ServerConfig, register func(*grpc.Server, int),
) *GrpcServers

StartGrpcServersWithConfigForTest starts multiple GRPC servers with given configurations.

type StatusRetriever

type StatusRetriever interface {
	GetTransactionsStatus(context.Context, *protoblocktx.QueryStatus, ...grpc.CallOption) (
		*protoblocktx.TransactionsStatus, error,
	)
}

StatusRetriever provides implementation retrieve status of given transaction identifiers.

Jump to

Keyboard shortcuts

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