asynqtest

package
v0.17.8 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package asynqtest defines test helpers for asynq and its internal packages.

Index

Constants

This section is empty.

Variables

View Source
var IgnoreIDOpt = cmpopts.IgnoreFields(base.TaskMessage{}, "ID")

IgnoreIDOpt is an cmp.Option to ignore ID field in task messages when comparing.

View Source
var SortMsgOpt = cmp.Transformer("SortTaskMessages", func(in []*base.TaskMessage) []*base.TaskMessage {
	out := append([]*base.TaskMessage(nil), in...)
	sort.Slice(out, func(i, j int) bool {
		return out[i].ID.String() < out[j].ID.String()
	})
	return out
})

SortMsgOpt is a cmp.Option to sort base.TaskMessage for comparing slice of task messages.

View Source
var SortSchedulerEnqueueEventOpt = cmp.Transformer("SortSchedulerEnqueueEvent", func(in []*base.SchedulerEnqueueEvent) []*base.SchedulerEnqueueEvent {
	out := append([]*base.SchedulerEnqueueEvent(nil), in...)
	sort.Slice(out, func(i, j int) bool {
		return out[i].EnqueuedAt.Unix() < out[j].EnqueuedAt.Unix()
	})
	return out
})

SortSchedulerEnqueueEventOpt is a cmp.Option to sort base.SchedulerEnqueueEvent for comparing slice of events.

View Source
var SortSchedulerEntryOpt = cmp.Transformer("SortSchedulerEntry", func(in []*base.SchedulerEntry) []*base.SchedulerEntry {
	out := append([]*base.SchedulerEntry(nil), in...)
	sort.Slice(out, func(i, j int) bool {
		return out[i].Spec < out[j].Spec
	})
	return out
})

SortSchedulerEntryOpt is a cmp.Option to sort base.SchedulerEntry for comparing slice of entries.

View Source
var SortServerInfoOpt = cmp.Transformer("SortServerInfo", func(in []*base.ServerInfo) []*base.ServerInfo {
	out := append([]*base.ServerInfo(nil), in...)
	sort.Slice(out, func(i, j int) bool {
		if out[i].Host != out[j].Host {
			return out[i].Host < out[j].Host
		}
		return out[i].PID < out[j].PID
	})
	return out
})

SortServerInfoOpt is a cmp.Option to sort base.ServerInfo for comparing slice of process info.

View Source
var SortStringSliceOpt = cmp.Transformer("SortStringSlice", func(in []string) []string {
	out := append([]string(nil), in...)
	sort.Strings(out)
	return out
})

SortStringSliceOpt is a cmp.Option to sort string slice.

View Source
var SortWorkerInfoOpt = cmp.Transformer("SortWorkerInfo", func(in []*base.WorkerInfo) []*base.WorkerInfo {
	out := append([]*base.WorkerInfo(nil), in...)
	sort.Slice(out, func(i, j int) bool {
		return out[i].ID < out[j].ID
	})
	return out
})

SortWorkerInfoOpt is a cmp.Option to sort base.WorkerInfo for comparing slice of worker info.

View Source
var SortZSetEntryOpt = cmp.Transformer("SortZSetEntries", func(in []base.Z) []base.Z {
	out := append([]base.Z(nil), in...)
	sort.Slice(out, func(i, j int) bool {
		return out[i].Message.ID.String() < out[j].Message.ID.String()
	})
	return out
})

SortZSetEntryOpt is an cmp.Option to sort ZSetEntry for comparing slice of zset entries.

Functions

func EquateInt64Approx

func EquateInt64Approx(margin int64) cmp.Option

EquateInt64Approx returns a Comparer option that treats int64 values to be equal if they are within the given margin.

func FlushDB

func FlushDB(tb testing.TB, r redis.UniversalClient)

FlushDB deletes all the keys of the currently selected DB.

func GetActiveMessages

func GetActiveMessages(tb testing.TB, r redis.UniversalClient, qname string) []*base.TaskMessage

GetActiveMessages returns all active messages in the given queue.

func GetArchivedEntries

func GetArchivedEntries(tb testing.TB, r redis.UniversalClient, qname string) []base.Z

GetArchivedEntries returns all archived messages and its score in the given queue.

func GetArchivedMessages

func GetArchivedMessages(tb testing.TB, r redis.UniversalClient, qname string) []*base.TaskMessage

GetArchivedMessages returns all archived messages in the given queue.

func GetDeadlinesEntries

func GetDeadlinesEntries(tb testing.TB, r redis.UniversalClient, qname string) []base.Z

GetDeadlinesEntries returns all task messages and its score in the deadlines set for the given queue.

func GetPendingMessages

func GetPendingMessages(tb testing.TB, r redis.UniversalClient, qname string) []*base.TaskMessage

GetPendingMessages returns all pending messages in the given queue.

func GetRetryEntries

func GetRetryEntries(tb testing.TB, r redis.UniversalClient, qname string) []base.Z

GetRetryEntries returns all retry messages and its score in the given queue.

func GetRetryMessages

func GetRetryMessages(tb testing.TB, r redis.UniversalClient, qname string) []*base.TaskMessage

GetRetryMessages returns all retry messages in the given queue.

func GetScheduledEntries

func GetScheduledEntries(tb testing.TB, r redis.UniversalClient, qname string) []base.Z

GetScheduledEntries returns all scheduled messages and its score in the given queue.

func GetScheduledMessages

func GetScheduledMessages(tb testing.TB, r redis.UniversalClient, qname string) []*base.TaskMessage

GetScheduledMessages returns all scheduled task messages in the given queue.

func MustMarshal

func MustMarshal(tb testing.TB, msg *base.TaskMessage) string

MustMarshal marshals given task message and returns a json string. Calling test will fail if marshaling errors out.

func MustMarshalSlice

func MustMarshalSlice(tb testing.TB, msgs []*base.TaskMessage) []string

MustMarshalSlice marshals a slice of task messages and return a slice of json strings. Calling test will fail if marshaling errors out.

func MustUnmarshal

func MustUnmarshal(tb testing.TB, data string) *base.TaskMessage

MustUnmarshal unmarshals given string into task message struct. Calling test will fail if unmarshaling errors out.

func MustUnmarshalSlice

func MustUnmarshalSlice(tb testing.TB, data []string) []*base.TaskMessage

MustUnmarshalSlice unmarshals a slice of strings into a slice of task message structs. Calling test will fail if marshaling errors out.

func NewTaskMessage

func NewTaskMessage(taskType string, payload map[string]interface{}) *base.TaskMessage

NewTaskMessage returns a new instance of TaskMessage given a task type and payload.

func NewTaskMessageWithQueue

func NewTaskMessageWithQueue(taskType string, payload map[string]interface{}, qname string) *base.TaskMessage

NewTaskMessageWithQueue returns a new instance of TaskMessage given a task type, payload and queue name.

func SeedActiveQueue

func SeedActiveQueue(tb testing.TB, r redis.UniversalClient, msgs []*base.TaskMessage, qname string)

SeedActiveQueue initializes the active queue with the given messages.

func SeedAllActiveQueues

func SeedAllActiveQueues(tb testing.TB, r redis.UniversalClient, active map[string][]*base.TaskMessage)

SeedAllActiveQueues initializes all of the specified active queues with the given messages.

func SeedAllArchivedQueues

func SeedAllArchivedQueues(tb testing.TB, r redis.UniversalClient, archived map[string][]base.Z)

SeedAllArchivedQueues initializes all of the specified archived queues with the given entries.

func SeedAllDeadlines

func SeedAllDeadlines(tb testing.TB, r redis.UniversalClient, deadlines map[string][]base.Z)

SeedAllDeadlines initializes all of the deadlines with the given entries.

func SeedAllPendingQueues

func SeedAllPendingQueues(tb testing.TB, r redis.UniversalClient, pending map[string][]*base.TaskMessage)

SeedAllPendingQueues initializes all of the specified queues with the given messages.

pending maps a queue name to a list of messages.

func SeedAllRetryQueues

func SeedAllRetryQueues(tb testing.TB, r redis.UniversalClient, retry map[string][]base.Z)

SeedAllRetryQueues initializes all of the specified retry queues with the given entries.

func SeedAllScheduledQueues

func SeedAllScheduledQueues(tb testing.TB, r redis.UniversalClient, scheduled map[string][]base.Z)

SeedAllScheduledQueues initializes all of the specified scheduled queues with the given entries.

func SeedArchivedQueue

func SeedArchivedQueue(tb testing.TB, r redis.UniversalClient, entries []base.Z, qname string)

SeedArchivedQueue initializes the archived queue with the given messages.

func SeedDeadlines

func SeedDeadlines(tb testing.TB, r redis.UniversalClient, entries []base.Z, qname string)

SeedDeadlines initializes the deadlines set with the given entries.

func SeedPendingQueue

func SeedPendingQueue(tb testing.TB, r redis.UniversalClient, msgs []*base.TaskMessage, qname string)

SeedPendingQueue initializes the specified queue with the given messages.

func SeedRetryQueue

func SeedRetryQueue(tb testing.TB, r redis.UniversalClient, entries []base.Z, qname string)

SeedRetryQueue initializes the retry queue with the given messages.

func SeedScheduledQueue

func SeedScheduledQueue(tb testing.TB, r redis.UniversalClient, entries []base.Z, qname string)

SeedScheduledQueue initializes the scheduled queue with the given messages.

func TaskMessageAfterRetry

func TaskMessageAfterRetry(t base.TaskMessage, errMsg string) *base.TaskMessage

TaskMessageAfterRetry returns an updated copy of t after retry. It increments retry count and sets the error message.

func TaskMessageWithError

func TaskMessageWithError(t base.TaskMessage, errMsg string) *base.TaskMessage

TaskMessageWithError returns an updated copy of t with the given error message.

Types

This section is empty.

Jump to

Keyboard shortcuts

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