mirror of
https://github.com/hibiken/asynq.git
synced 2024-12-24 23:02:18 +08:00
Add test for client
This commit is contained in:
parent
d53e5d3350
commit
634af38e3a
52
client_test.go
Normal file
52
client_test.go
Normal file
@ -0,0 +1,52 @@
|
||||
package asynq
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestClient(t *testing.T) {
|
||||
r := setup(t)
|
||||
client := &Client{rdb: r}
|
||||
|
||||
tests := []struct {
|
||||
task *Task
|
||||
processAt time.Time
|
||||
wantQueueSize int64
|
||||
wantScheduledSize int64
|
||||
}{
|
||||
{
|
||||
task: &Task{Type: "send_email", Payload: map[string]interface{}{"to": "customer@gmail.com", "from": "merchant@example.com"}},
|
||||
processAt: time.Now(),
|
||||
wantQueueSize: 1,
|
||||
wantScheduledSize: 0,
|
||||
},
|
||||
{
|
||||
task: &Task{Type: "send_email", Payload: map[string]interface{}{"to": "customer@gmail.com", "from": "merchant@example.com"}},
|
||||
processAt: time.Now().Add(2 * time.Hour),
|
||||
wantQueueSize: 0,
|
||||
wantScheduledSize: 1,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range tests {
|
||||
// clean up db before each test case.
|
||||
if err := r.client.FlushDB().Err(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
err := client.Process(tc.task, tc.processAt)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
continue
|
||||
}
|
||||
|
||||
if l := r.client.LLen(defaultQueue).Val(); l != tc.wantQueueSize {
|
||||
t.Errorf("%q has length %d, want %d", defaultQueue, l, tc.wantQueueSize)
|
||||
}
|
||||
|
||||
if l := r.client.ZCard(scheduled).Val(); l != tc.wantScheduledSize {
|
||||
t.Errorf("%q has length %d, want %d", scheduled, l, tc.wantScheduledSize)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user