mirror of
https://github.com/hibiken/asynq.git
synced 2024-12-25 07:12:17 +08:00
scheduler_test
This commit is contained in:
parent
7c65581fd7
commit
f75581d4e2
@ -209,7 +209,7 @@ func TestSchedulerPostAndPreEnqueueHandler(t *testing.T) {
|
||||
postMu.Unlock()
|
||||
}
|
||||
|
||||
func TestSchedulerWithCustomEntryIDGeneratorFunc(t *testing.T) {
|
||||
func TestSchedulerWithCustomEntryIDOpt(t *testing.T) {
|
||||
tests := []struct {
|
||||
cronspec string
|
||||
task *Task
|
||||
@ -221,7 +221,8 @@ func TestSchedulerWithCustomEntryIDGeneratorFunc(t *testing.T) {
|
||||
{
|
||||
cronspec: "@every 3s",
|
||||
task: NewTask("task1", nil),
|
||||
opts: []Option{MaxRetry(10),
|
||||
opts: []Option{
|
||||
MaxRetry(10),
|
||||
SchedulerEntryID("entry1"),
|
||||
},
|
||||
wait: 10 * time.Second,
|
||||
@ -235,43 +236,22 @@ func TestSchedulerWithCustomEntryIDGeneratorFunc(t *testing.T) {
|
||||
Queue: "default",
|
||||
ID: "entry1",
|
||||
},
|
||||
{
|
||||
Type: "task1",
|
||||
Payload: nil,
|
||||
Retry: 10,
|
||||
Timeout: int64(defaultTimeout.Seconds()),
|
||||
Queue: "default",
|
||||
ID: "entry1",
|
||||
},
|
||||
{
|
||||
Type: "task1",
|
||||
Payload: nil,
|
||||
Retry: 10,
|
||||
Timeout: int64(defaultTimeout.Seconds()),
|
||||
Queue: "default",
|
||||
ID: "entry1",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
r := setup(t)
|
||||
|
||||
for _, tc := range tests {
|
||||
scheduler := NewScheduler(getRedisConnOpt(t), nil)
|
||||
if _, err := scheduler.Register(tc.cronspec, tc.task, tc.opts...); err != nil {
|
||||
entryID, err := scheduler.Register(tc.cronspec, tc.task, tc.opts...)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := scheduler.Start(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
time.Sleep(tc.wait)
|
||||
scheduler.Shutdown()
|
||||
|
||||
got := testutil.GetPendingMessages(t, r, tc.queue)
|
||||
if diff := cmp.Diff(tc.want, got, testutil.IgnoreIDOpt); diff != "" {
|
||||
t.Errorf("mismatch found in queue %q: (-want,+got)\n%s", tc.queue, diff)
|
||||
if entryID != "entry1" {
|
||||
t.Errorf("entryID = %q, want %q", entryID, "entry1")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user