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()
|
postMu.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSchedulerWithCustomEntryIDGeneratorFunc(t *testing.T) {
|
func TestSchedulerWithCustomEntryIDOpt(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
cronspec string
|
cronspec string
|
||||||
task *Task
|
task *Task
|
||||||
@ -221,7 +221,8 @@ func TestSchedulerWithCustomEntryIDGeneratorFunc(t *testing.T) {
|
|||||||
{
|
{
|
||||||
cronspec: "@every 3s",
|
cronspec: "@every 3s",
|
||||||
task: NewTask("task1", nil),
|
task: NewTask("task1", nil),
|
||||||
opts: []Option{MaxRetry(10),
|
opts: []Option{
|
||||||
|
MaxRetry(10),
|
||||||
SchedulerEntryID("entry1"),
|
SchedulerEntryID("entry1"),
|
||||||
},
|
},
|
||||||
wait: 10 * time.Second,
|
wait: 10 * time.Second,
|
||||||
@ -235,43 +236,22 @@ func TestSchedulerWithCustomEntryIDGeneratorFunc(t *testing.T) {
|
|||||||
Queue: "default",
|
Queue: "default",
|
||||||
ID: "entry1",
|
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 {
|
for _, tc := range tests {
|
||||||
scheduler := NewScheduler(getRedisConnOpt(t), nil)
|
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)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := scheduler.Start(); err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
time.Sleep(tc.wait)
|
time.Sleep(tc.wait)
|
||||||
scheduler.Shutdown()
|
scheduler.Shutdown()
|
||||||
|
|
||||||
got := testutil.GetPendingMessages(t, r, tc.queue)
|
if entryID != "entry1" {
|
||||||
if diff := cmp.Diff(tc.want, got, testutil.IgnoreIDOpt); diff != "" {
|
t.Errorf("entryID = %q, want %q", entryID, "entry1")
|
||||||
t.Errorf("mismatch found in queue %q: (-want,+got)\n%s", tc.queue, diff)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user