2
0
mirror of https://github.com/hibiken/asynq.git synced 2024-12-24 23:02:18 +08:00

scheduler_test

This commit is contained in:
ilkerkorkut 2023-03-01 01:53:16 +03:00
parent 7c65581fd7
commit f75581d4e2
No known key found for this signature in database

View File

@ -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")
}
}
}