tests

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2023 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddSimpleMessagesParallel

func AddSimpleMessagesParallel(t *testing.T, messagesCount int, publisher message.Publisher, topicName string, publishers int) message.Messages

AddSimpleMessagesParallel publishes provided number of simple messages without a payload using the provided number of publishers (goroutines).

func AssertAllMessagesReceived

func AssertAllMessagesReceived(t *testing.T, sent message.Messages, received message.Messages) bool

AssertAllMessagesReceived checks if all messages were received, ignoring the order and assuming that they are already deduplicated.

func AssertMessagesMetadata

func AssertMessagesMetadata(t *testing.T, key string, expectedValues map[string]string, received []*message.Message) bool

AssertMessagesMetadata checks if metadata of all received messages is the same as in expectedValues.

func AssertMessagesPayloads

func AssertMessagesPayloads(
	t *testing.T,
	expectedPayloads map[string][]byte,
	received []*message.Message,
) bool

AssertMessagesPayloads check if received messages have the same payload as expected in expectedPayloads.

func BenchSubscriber

func BenchSubscriber(b *testing.B, pubSubConstructor BenchmarkPubSubConstructor)

BenchSubscriber runs benchmark on a message Subscriber.

func MissingMessages

func MissingMessages(expected message.Messages, received message.Messages) []string

MissingMessages returns a list of missing messages UUIDs.

func PublishSimpleMessages

func PublishSimpleMessages(t *testing.T, messagesCount int, publisher message.Publisher, topicName string) message.Messages

PublishSimpleMessages publishes provided number of simple messages without a payload.

func RunOnlyFastTests

func RunOnlyFastTests() bool

RunOnlyFastTests returns true if -short flag was provided -race was not provided. Useful for excluding some slow tests.

func TestConcurrentClose

func TestConcurrentClose(
	t *testing.T,
	tCtx TestContext,
	createPubSub PubSubConstructor,
)

TestConcurrentClose tests if the Pub/Sub works correctly when subscribers are being closed concurrently.

func TestConcurrentSubscribe

func TestConcurrentSubscribe(
	t *testing.T,
	tCtx TestContext,
	pubSubConstructor PubSubConstructor,
)

TestConcurrentSubscribe tests subscribing to messages by multiple concurrent subscribers.

func TestConcurrentSubscribeMultipleTopics

func TestConcurrentSubscribeMultipleTopics(
	t *testing.T,
	tCtx TestContext,
	pubSubConstructor PubSubConstructor,
)

TestConcurrentSubscribeMultipleTopics tests subscribing to messages by concurrent subscribers on multiple topics.

func TestConsumerGroups

func TestConsumerGroups(
	t *testing.T,
	tCtx TestContext,
	pubSubConstructor ConsumerGroupPubSubConstructor,
)

TestConsumerGroups tests if the consumer groups feature behaves correctly. This test is skipped for Pub/Sub that don't support ConsumerGroups feature.

func TestContinueAfterErrors

func TestContinueAfterErrors(
	t *testing.T,
	tCtx TestContext,
	createPubSub PubSubConstructor,
)

TestContinueAfterErrors tests if messages are processed again after an initial failure.

func TestContinueAfterSubscribeClose

func TestContinueAfterSubscribeClose(
	t *testing.T,
	tCtx TestContext,
	createPubSub PubSubConstructor,
)

TestContinueAfterSubscribeClose checks, that we don't lose messages after closing subscriber.

func TestMessageCtx

func TestMessageCtx(
	t *testing.T,
	tCtx TestContext,
	pubSubConstructor PubSubConstructor,
)

TestMessageCtx tests if the Message's Context works correctly.

func TestNewSubscriberReceivesOldMessages

func TestNewSubscriberReceivesOldMessages(
	t *testing.T,
	tCtx TestContext,
	pubSubConstructor PubSubConstructor,
)

TestNewSubscriberReceivesOldMessages tests if a new subscriber receives previously published messages.

func TestNoAck

func TestNoAck(
	t *testing.T,
	tCtx TestContext,
	pubSubConstructor PubSubConstructor,
)

TestNoAck tests if no new messages are received by the subscriber until the previous message is acknowledged. This test is skipped for Pub/Subs that don't support GuaranteedOrder feature.

func TestPubSub

func TestPubSub(
	t *testing.T,
	features Features,
	pubSubConstructor PubSubConstructor,
	consumerGroupPubSubConstructor ConsumerGroupPubSubConstructor,
)

TestPubSub is a universal test suite. Every Pub/Sub implementation should pass it before it's considered production ready.

Execution of the tests may be a bit different for every Pub/Sub. You can configure it by changing provided Features.

func TestPubSubStressTest

func TestPubSubStressTest(
	t *testing.T,
	features Features,
	pubSubConstructor PubSubConstructor,
	consumerGroupPubSubConstructor ConsumerGroupPubSubConstructor,
)

TestPubSubStressTest runs stress tests on a chosen Pub/Sub.

func TestPublishSubscribe

func TestPublishSubscribe(
	t *testing.T,
	tCtx TestContext,
	pubSubConstructor PubSubConstructor,
)

TestPublishSubscribe runs basic publish and subscribe tests on a chosen Pub/Sub.

func TestPublishSubscribeInOrder

func TestPublishSubscribeInOrder(
	t *testing.T,
	tCtx TestContext,
	pubSubConstructor PubSubConstructor,
)

TestPublishSubscribeInOrder tests if published messages are received in a proper order. This test is skipped for Pub/Subs that don't support GuaranteedOrder feature.

func TestPublisherClose

func TestPublisherClose(
	t *testing.T,
	tCtx TestContext,
	pubSubConstructor PubSubConstructor,
)

TestPublisherClose sends big amount of messages and them run close to ensure that messages are not lost during adding.

func TestReconnect

func TestReconnect(
	t *testing.T,
	tCtx TestContext,
	pubSubConstructor PubSubConstructor,
)

TestReconnect tests if reconnecting to a Pub/Sub works correctly.

func TestResendOnError

func TestResendOnError(
	t *testing.T,
	tCtx TestContext,
	pubSubConstructor PubSubConstructor,
)

TestResendOnError tests if messages are re-delivered after the subscriber fails to process them.

func TestSubscribeCtx

func TestSubscribeCtx(
	t *testing.T,
	tCtx TestContext,
	pubSubConstructor PubSubConstructor,
)

TestSubscribeCtx tests if the Subscriber's Context works correctly.

func TestTopic

func TestTopic(
	t *testing.T,
	tCtx TestContext,
	pubSubConstructor PubSubConstructor,
)

TestTopic tests if different topics work correctly in a Pub/Sub.

Types

type BenchmarkPubSubConstructor

type BenchmarkPubSubConstructor func(n int) (message.Publisher, message.Subscriber)

BenchmarkPubSubConstructor is a function that creates a Publisher and Subscriber to be used for benchmarks.

type ConsumerGroupPubSubConstructor

type ConsumerGroupPubSubConstructor func(t *testing.T, consumerGroup string) (message.Publisher, message.Subscriber)

ConsumerGroupPubSubConstructor is a function that creates a Publisher and a Subscriber that use given consumer group.

type Features

type Features struct {
	// ConsumerGroups should be true, if consumer groups are supported.
	ConsumerGroups bool

	// ExactlyOnceDelivery should be true, if exactly-once delivery is supported.
	ExactlyOnceDelivery bool

	// GuaranteedOrder should be true, if order of messages is guaranteed.
	GuaranteedOrder bool

	// Some Pub/Subs guarantee the order only when one subscriber is subscribed at a time.
	GuaranteedOrderWithSingleSubscriber bool

	// Persistent should be true, if messages are persistent between multiple instancees of a Pub/Sub
	// (in practice, only GoChannel doesn't support that).
	Persistent bool

	// RestartServiceCommand is a command to test reconnects. It should restart the message broker.
	// Example: []string{"docker", "restart", "rabbitmq"}
	RestartServiceCommand []string

	// RequireSingleInstance must be true,if a PubSub requires a single instance to work properly
	// (for example: GoChannel implementation).
	RequireSingleInstance bool

	// NewSubscriberReceivesOldMessages should be set to true if messages are persisted even
	// if they are already consumed (for example, like in Kafka).
	NewSubscriberReceivesOldMessages bool
}

Features are used to configure Pub/Subs implementations behaviour. Different features set decides also which, and how tests should be run.

type PubSubConstructor

type PubSubConstructor func(t *testing.T) (message.Publisher, message.Subscriber)

PubSubConstructor is a function that creates a Publisher and a Subscriber.

type SimpleMessage

type SimpleMessage struct {
	Num int `json:"num"`
}

SimpleMessage is deprecated: not used anywhere internally

type TestContext

type TestContext struct {
	// Unique ID of the test
	TestID TestID

	// PubSub features
	Features Features
}

TestContext is a collection of values that belong to a single test.

type TestID

type TestID string

TestID is a unique ID of a test.

func NewTestID

func NewTestID() TestID

NewTestID returns a new unique TestID.

Jump to

Keyboard shortcuts

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