Documentation ¶
Overview ¶
Package testutil defines test helpers for asynq and its internal packages.
Index ¶
- Variables
- func AssertRedisLists(t *testing.T, r valkey.UniversalClient, wantLists map[string][]string)
- func AssertRedisSets(t *testing.T, r valkey.UniversalClient, wantSets map[string][]string)
- func AssertRedisZSets(t *testing.T, r valkey.UniversalClient, wantZSets map[string][]valkey.Z)
- func EquateInt64Approx(margin int64) cmp.Option
- func FlushDB(tb testing.TB, r valkey.UniversalClient)
- func GetActiveMessages(tb testing.TB, r valkey.UniversalClient, qname string) []*base.TaskMessage
- func GetArchivedEntries(tb testing.TB, r valkey.UniversalClient, qname string) []base.Z
- func GetArchivedMessages(tb testing.TB, r valkey.UniversalClient, qname string) []*base.TaskMessage
- func GetCompletedEntries(tb testing.TB, r valkey.UniversalClient, qname string) []base.Z
- func GetCompletedMessages(tb testing.TB, r valkey.UniversalClient, qname string) []*base.TaskMessage
- func GetGroupEntries(tb testing.TB, r valkey.UniversalClient, qname, groupKey string) []base.Z
- func GetLeaseEntries(tb testing.TB, r valkey.UniversalClient, qname string) []base.Z
- func GetPendingMessages(tb testing.TB, r valkey.UniversalClient, qname string) []*base.TaskMessage
- func GetRetryEntries(tb testing.TB, r valkey.UniversalClient, qname string) []base.Z
- func GetRetryMessages(tb testing.TB, r valkey.UniversalClient, qname string) []*base.TaskMessage
- func GetScheduledEntries(tb testing.TB, r valkey.UniversalClient, qname string) []base.Z
- func GetScheduledMessages(tb testing.TB, r valkey.UniversalClient, qname string) []*base.TaskMessage
- func JSON(kv map[string]interface{}) []byte
- func MustMarshal(tb testing.TB, msg *base.TaskMessage) string
- func MustUnmarshal(tb testing.TB, data string) *base.TaskMessage
- func NewLeaseWithClock(expirationTime time.Time, clock timeutil.Clock) *base.Lease
- func NewTaskMessage(taskType string, payload []byte) *base.TaskMessage
- func NewTaskMessageWithQueue(taskType string, payload []byte, qname string) *base.TaskMessage
- func SeedActiveQueue(tb testing.TB, r valkey.UniversalClient, msgs []*base.TaskMessage, ...)
- func SeedAggregationSet(tb testing.TB, r valkey.UniversalClient, entries []base.Z, ...)
- func SeedAllActiveQueues(tb testing.TB, r valkey.UniversalClient, active map[string][]*base.TaskMessage)
- func SeedAllArchivedQueues(tb testing.TB, r valkey.UniversalClient, archived map[string][]base.Z)
- func SeedAllCompletedQueues(tb testing.TB, r valkey.UniversalClient, completed map[string][]base.Z)
- func SeedAllGroups(tb testing.TB, r valkey.UniversalClient, groups map[string]map[string][]base.Z)
- func SeedAllLease(tb testing.TB, r valkey.UniversalClient, lease map[string][]base.Z)
- func SeedAllPendingQueues(tb testing.TB, r valkey.UniversalClient, ...)
- func SeedAllRetryQueues(tb testing.TB, r valkey.UniversalClient, retry map[string][]base.Z)
- func SeedAllScheduledQueues(tb testing.TB, r valkey.UniversalClient, scheduled map[string][]base.Z)
- func SeedArchivedQueue(tb testing.TB, r valkey.UniversalClient, entries []base.Z, qname string)
- func SeedCompletedQueue(tb testing.TB, r valkey.UniversalClient, entries []base.Z, qname string)
- func SeedGroup(tb testing.TB, r valkey.UniversalClient, entries []base.Z, qname, gname string)
- func SeedLease(tb testing.TB, r valkey.UniversalClient, entries []base.Z, qname string)
- func SeedPendingQueue(tb testing.TB, r valkey.UniversalClient, msgs []*base.TaskMessage, ...)
- func SeedRedisLists(tb testing.TB, r valkey.UniversalClient, lists map[string][]string)
- func SeedRedisSet(tb testing.TB, r valkey.UniversalClient, key string, members []string)
- func SeedRedisSets(tb testing.TB, r valkey.UniversalClient, sets map[string][]string)
- func SeedRedisZSets(tb testing.TB, r valkey.UniversalClient, zsets map[string][]valkey.Z)
- func SeedRetryQueue(tb testing.TB, r valkey.UniversalClient, entries []base.Z, qname string)
- func SeedScheduledQueue(tb testing.TB, r valkey.UniversalClient, entries []base.Z, qname string)
- func SeedTasks(tb testing.TB, r valkey.UniversalClient, taskData []*TaskSeedData)
- func TaskMessageAfterRetry(t base.TaskMessage, errMsg string, failedAt time.Time) *base.TaskMessage
- func TaskMessageWithCompletedAt(t base.TaskMessage, completedAt time.Time) *base.TaskMessage
- func TaskMessageWithError(t base.TaskMessage, errMsg string, failedAt time.Time) *base.TaskMessage
- type TaskMessageBuilder
- func (b *TaskMessageBuilder) Build() *base.TaskMessage
- func (b *TaskMessageBuilder) SetDeadline(deadline time.Time) *TaskMessageBuilder
- func (b *TaskMessageBuilder) SetGroup(gname string) *TaskMessageBuilder
- func (b *TaskMessageBuilder) SetPayload(payload []byte) *TaskMessageBuilder
- func (b *TaskMessageBuilder) SetQueue(qname string) *TaskMessageBuilder
- func (b *TaskMessageBuilder) SetRetry(n int) *TaskMessageBuilder
- func (b *TaskMessageBuilder) SetTimeout(timeout time.Duration) *TaskMessageBuilder
- func (b *TaskMessageBuilder) SetType(typename string) *TaskMessageBuilder
- type TaskSeedData
Constants ¶
This section is empty.
Variables ¶
var IgnoreIDOpt = cmpopts.IgnoreFields(base.TaskMessage{}, "ID")
IgnoreIDOpt is an cmp.Option to ignore ID field in task messages when comparing.
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 < out[j].ID }) return out })
SortMsgOpt is a cmp.Option to sort base.TaskMessage for comparing slice of task messages.
var SortRedisZSetEntryOpt = cmp.Transformer("SortZSetEntries", func(in []valkey.Z) []valkey.Z { out := append([]valkey.Z(nil), in...) sort.Slice(out, func(i, j int) bool { if _, ok := out[i].Member.(string); ok { return out[i].Member.(string) < out[j].Member.(string) } return out[i].Score < out[j].Score }) return out })
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.
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.
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.
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.
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.
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 < out[j].Message.ID }) return out })
SortZSetEntryOpt is an cmp.Option to sort ZSetEntry for comparing slice of zset entries.
Functions ¶
func AssertRedisLists ¶
func AssertRedisSets ¶
func AssertRedisZSets ¶
func EquateInt64Approx ¶
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 valkey.UniversalClient)
FlushDB deletes all the keys of the currently selected DB.
func GetActiveMessages ¶
func GetActiveMessages(tb testing.TB, r valkey.UniversalClient, qname string) []*base.TaskMessage
GetActiveMessages returns all active messages in the given queue. It also asserts the state field of the task.
func GetArchivedEntries ¶
GetArchivedEntries returns all archived messages and its score in the given queue. It also asserts the state field of the task.
func GetArchivedMessages ¶
func GetArchivedMessages(tb testing.TB, r valkey.UniversalClient, qname string) []*base.TaskMessage
GetArchivedMessages returns all archived messages in the given queue. It also asserts the state field of the task.
func GetCompletedEntries ¶
GetCompletedEntries returns all completed messages and its score in the given queue. It also asserts the state field of the task.
func GetCompletedMessages ¶
func GetCompletedMessages(tb testing.TB, r valkey.UniversalClient, qname string) []*base.TaskMessage
GetCompletedMessages returns all completed task messages in the given queue. It also asserts the state field of the task.
func GetGroupEntries ¶
GetGroupEntries returns all scheduled messages and its score in the given queue. It also asserts the state field of the task.
func GetLeaseEntries ¶
GetLeaseEntries returns all task IDs and its score in the lease set for the given queue. It also asserts the state field of the task.
func GetPendingMessages ¶
func GetPendingMessages(tb testing.TB, r valkey.UniversalClient, qname string) []*base.TaskMessage
GetPendingMessages returns all pending messages in the given queue. It also asserts the state field of the task.
func GetRetryEntries ¶
GetRetryEntries returns all retry messages and its score in the given queue. It also asserts the state field of the task.
func GetRetryMessages ¶
func GetRetryMessages(tb testing.TB, r valkey.UniversalClient, qname string) []*base.TaskMessage
GetRetryMessages returns all retry messages in the given queue. It also asserts the state field of the task.
func GetScheduledEntries ¶
GetScheduledEntries returns all scheduled messages and its score in the given queue. It also asserts the state field of the task.
func GetScheduledMessages ¶
func GetScheduledMessages(tb testing.TB, r valkey.UniversalClient, qname string) []*base.TaskMessage
GetScheduledMessages returns all scheduled task messages in the given queue. It also asserts the state field of the task.
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 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 NewLeaseWithClock ¶
NewLeaseWithClock returns a new lease with the given expiration time and clock.
func NewTaskMessage ¶
func NewTaskMessage(taskType string, payload []byte) *base.TaskMessage
NewTaskMessage returns a new instance of TaskMessage given a task type and payload.
func NewTaskMessageWithQueue ¶
func NewTaskMessageWithQueue(taskType string, payload []byte, 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 valkey.UniversalClient, msgs []*base.TaskMessage, qname string)
SeedActiveQueue initializes the active queue with the given messages.
func SeedAggregationSet ¶
func SeedAllActiveQueues ¶
func SeedAllActiveQueues(tb testing.TB, r valkey.UniversalClient, active map[string][]*base.TaskMessage)
SeedAllActiveQueues initializes all of the specified active queues with the given messages.
func SeedAllArchivedQueues ¶
SeedAllArchivedQueues initializes all of the specified archived queues with the given entries.
func SeedAllCompletedQueues ¶
SeedAllCompletedQueues initializes all of the completed queues with the given entries.
func SeedAllGroups ¶
SeedAllGroups initializes all groups in all queues. The map maps queue names to group names which maps to a list of task messages and the time it was added to the group.
func SeedAllLease ¶
SeedAllLease initializes all of the lease sets with the given entries.
func SeedAllPendingQueues ¶
func SeedAllPendingQueues(tb testing.TB, r valkey.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 ¶
SeedAllRetryQueues initializes all of the specified retry queues with the given entries.
func SeedAllScheduledQueues ¶
SeedAllScheduledQueues initializes all of the specified scheduled queues with the given entries.
func SeedArchivedQueue ¶
SeedArchivedQueue initializes the archived queue with the given messages.
func SeedCompletedQueue ¶
SeedCompletedQueue initializes the completed set with the given entries.
func SeedPendingQueue ¶
func SeedPendingQueue(tb testing.TB, r valkey.UniversalClient, msgs []*base.TaskMessage, qname string)
SeedPendingQueue initializes the specified queue with the given messages.
func SeedRedisLists ¶
func SeedRedisSet ¶
func SeedRedisSets ¶
func SeedRedisZSets ¶
func SeedRetryQueue ¶
SeedRetryQueue initializes the retry queue with the given messages.
func SeedScheduledQueue ¶
SeedScheduledQueue initializes the scheduled queue with the given messages.
func SeedTasks ¶
func SeedTasks(tb testing.TB, r valkey.UniversalClient, taskData []*TaskSeedData)
func TaskMessageAfterRetry ¶
func TaskMessageAfterRetry(t base.TaskMessage, errMsg string, failedAt time.Time) *base.TaskMessage
TaskMessageAfterRetry returns an updated copy of t after retry. It increments retry count and sets the error message and last_failed_at time.
func TaskMessageWithCompletedAt ¶
func TaskMessageWithCompletedAt(t base.TaskMessage, completedAt time.Time) *base.TaskMessage
TaskMessageWithCompletedAt returns an updated copy of t after completion.
func TaskMessageWithError ¶
func TaskMessageWithError(t base.TaskMessage, errMsg string, failedAt time.Time) *base.TaskMessage
TaskMessageWithError returns an updated copy of t with the given error message.
Types ¶
type TaskMessageBuilder ¶
type TaskMessageBuilder struct {
// contains filtered or unexported fields
}
func NewTaskMessageBuilder ¶
func NewTaskMessageBuilder() *TaskMessageBuilder
func (*TaskMessageBuilder) Build ¶
func (b *TaskMessageBuilder) Build() *base.TaskMessage
func (*TaskMessageBuilder) SetDeadline ¶
func (b *TaskMessageBuilder) SetDeadline(deadline time.Time) *TaskMessageBuilder
func (*TaskMessageBuilder) SetGroup ¶
func (b *TaskMessageBuilder) SetGroup(gname string) *TaskMessageBuilder
func (*TaskMessageBuilder) SetPayload ¶
func (b *TaskMessageBuilder) SetPayload(payload []byte) *TaskMessageBuilder
func (*TaskMessageBuilder) SetQueue ¶
func (b *TaskMessageBuilder) SetQueue(qname string) *TaskMessageBuilder
func (*TaskMessageBuilder) SetRetry ¶
func (b *TaskMessageBuilder) SetRetry(n int) *TaskMessageBuilder
func (*TaskMessageBuilder) SetTimeout ¶
func (b *TaskMessageBuilder) SetTimeout(timeout time.Duration) *TaskMessageBuilder
func (*TaskMessageBuilder) SetType ¶
func (b *TaskMessageBuilder) SetType(typename string) *TaskMessageBuilder
type TaskSeedData ¶
TaskSeedData holds the data required to seed tasks under the task key in test.