mirror of
https://github.com/hibiken/asynq.git
synced 2025-09-19 13:21:58 +08:00
Update Enqueue and Schedule commands in rdb
This commit is contained in:
@@ -34,10 +34,8 @@ func setup(t *testing.T) *RDB {
|
||||
func TestEnqueue(t *testing.T) {
|
||||
r := setup(t)
|
||||
t1 := h.NewTaskMessage("send_email", map[string]interface{}{"to": "exampleuser@gmail.com", "from": "noreply@example.com"})
|
||||
t2 := h.NewTaskMessage("generate_csv", map[string]interface{}{})
|
||||
t2.Queue = "csv"
|
||||
t3 := h.NewTaskMessage("sync", nil)
|
||||
t3.Queue = "low"
|
||||
t2 := h.NewTaskMessageWithQueue("generate_csv", map[string]interface{}{}, "csv")
|
||||
t3 := h.NewTaskMessageWithQueue("sync", nil, "low")
|
||||
|
||||
tests := []struct {
|
||||
msg *base.TaskMessage
|
||||
@@ -55,17 +53,16 @@ func TestEnqueue(t *testing.T) {
|
||||
t.Errorf("(*RDB).Enqueue(msg) = %v, want nil", err)
|
||||
}
|
||||
|
||||
qkey := base.QueueKey(tc.msg.Queue)
|
||||
gotEnqueued := h.GetEnqueuedMessages(t, r.client, tc.msg.Queue)
|
||||
if len(gotEnqueued) != 1 {
|
||||
t.Errorf("%q has length %d, want 1", qkey, len(gotEnqueued))
|
||||
t.Errorf("%q has length %d, want 1", base.QueueKey(tc.msg.Queue), len(gotEnqueued))
|
||||
continue
|
||||
}
|
||||
if diff := cmp.Diff(tc.msg, gotEnqueued[0]); diff != "" {
|
||||
t.Errorf("persisted data differed from the original input (-want, +got)\n%s", diff)
|
||||
}
|
||||
if !r.client.SIsMember(base.AllQueues, qkey).Val() {
|
||||
t.Errorf("%q is not a member of SET %q", qkey, base.AllQueues)
|
||||
if !r.client.SIsMember(base.AllQueues, tc.msg.Queue).Val() {
|
||||
t.Errorf("%q is not a member of SET %q", tc.msg.Queue, base.AllQueues)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -77,7 +74,7 @@ func TestEnqueueUnique(t *testing.T) {
|
||||
Type: "email",
|
||||
Payload: map[string]interface{}{"user_id": 123},
|
||||
Queue: base.DefaultQueueName,
|
||||
UniqueKey: "email:user_id=123:default",
|
||||
UniqueKey: base.UniqueKey(base.DefaultQueueName, "email", map[string]interface{}{"user_id": 123}),
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
@@ -103,12 +100,14 @@ func TestEnqueueUnique(t *testing.T) {
|
||||
tc.msg, tc.ttl, got, ErrDuplicateTask)
|
||||
continue
|
||||
}
|
||||
|
||||
gotTTL := r.client.TTL(tc.msg.UniqueKey).Val()
|
||||
if !cmp.Equal(tc.ttl.Seconds(), gotTTL.Seconds(), cmpopts.EquateApprox(0, 1)) {
|
||||
t.Errorf("TTL %q = %v, want %v", tc.msg.UniqueKey, gotTTL, tc.ttl)
|
||||
continue
|
||||
}
|
||||
if !r.client.SIsMember(base.AllQueues, tc.msg.Queue).Val() {
|
||||
t.Errorf("%q is not a member of SET %q", tc.msg.Queue, base.AllQueues)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -673,15 +672,20 @@ func TestSchedule(t *testing.T) {
|
||||
continue
|
||||
}
|
||||
|
||||
gotScheduled := h.GetScheduledEntries(t, r.client)
|
||||
gotScheduled := h.GetScheduledEntries(t, r.client, tc.msg.Queue)
|
||||
if len(gotScheduled) != 1 {
|
||||
t.Errorf("%s inserted %d items to %q, want 1 items inserted", desc, len(gotScheduled), base.ScheduledQueue)
|
||||
t.Errorf("%s inserted %d items to %q, want 1 items inserted",
|
||||
desc, len(gotScheduled), base.ScheduledKey(tc.msg.Queue))
|
||||
continue
|
||||
}
|
||||
if int64(gotScheduled[0].Score) != tc.processAt.Unix() {
|
||||
t.Errorf("%s inserted an item with score %d, want %d", desc, int64(gotScheduled[0].Score), tc.processAt.Unix())
|
||||
t.Errorf("%s inserted an item with score %d, want %d",
|
||||
desc, int64(gotScheduled[0].Score), tc.processAt.Unix())
|
||||
continue
|
||||
}
|
||||
if !r.client.SIsMember(base.AllQueues, tc.msg.Queue).Val() {
|
||||
t.Errorf("%q is not a member of SET %q", tc.msg.Queue, base.AllQueues)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -692,7 +696,7 @@ func TestScheduleUnique(t *testing.T) {
|
||||
Type: "email",
|
||||
Payload: map[string]interface{}{"user_id": 123},
|
||||
Queue: base.DefaultQueueName,
|
||||
UniqueKey: "email:user_id=123:default",
|
||||
UniqueKey: base.UniqueKey(base.DefaultQueueName, "email", map[string]interface{}{"user_id": 123}),
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
@@ -713,9 +717,9 @@ func TestScheduleUnique(t *testing.T) {
|
||||
continue
|
||||
}
|
||||
|
||||
gotScheduled := h.GetScheduledEntries(t, r.client)
|
||||
gotScheduled := h.GetScheduledEntries(t, r.client, tc.msg.Queue)
|
||||
if len(gotScheduled) != 1 {
|
||||
t.Errorf("%s inserted %d items to %q, want 1 items inserted", desc, len(gotScheduled), base.ScheduledQueue)
|
||||
t.Errorf("%s inserted %d items to %q, want 1 items inserted", desc, len(gotScheduled), base.ScheduledKey(tc.msg.Queue))
|
||||
continue
|
||||
}
|
||||
if int64(gotScheduled[0].Score) != tc.processAt.Unix() {
|
||||
@@ -734,6 +738,10 @@ func TestScheduleUnique(t *testing.T) {
|
||||
t.Errorf("TTL %q = %v, want %v", tc.msg.UniqueKey, gotTTL, tc.ttl)
|
||||
continue
|
||||
}
|
||||
if !r.client.SIsMember(base.AllQueues, tc.msg.Queue).Val() {
|
||||
t.Errorf("%q is not a member of SET %q", tc.msg.Queue, base.AllQueues)
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user