tests

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2020 License: MIT Imports: 20 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)

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,
)

func TestConcurrentSubscribe

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

func TestConsumerGroups

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

func TestContinueAfterErrors

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

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,
)

func TestNewSubscriberReceivesOldMessages

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

func TestNoAck

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

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,
)

func TestPublishSubscribe

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

func TestPublishSubscribeInOrder

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

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,
)

func TestResendOnError

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

func TestSubscribeCtx

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

func TestTopic

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

Types

type BenchmarkPubSubConstructor

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

type ConsumerGroupPubSubConstructor

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

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)

type SimpleMessage

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

deprecated: not used anywhere internally

type TestContext

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

	// PubSub features
	Features Features
}

type TestID

type TestID string

func NewTestID

func NewTestID() TestID

Jump to

Keyboard shortcuts

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