2
0
mirror of https://github.com/hibiken/asynq.git synced 2024-11-10 11:31:58 +08:00
asynq/background_test.go
2019-12-29 14:55:16 -08:00

46 lines
884 B
Go

package asynq
import (
"testing"
"time"
"github.com/go-redis/redis/v7"
"go.uber.org/goleak"
)
func TestBackground(t *testing.T) {
// https://github.com/go-redis/redis/issues/1029
ignoreOpt := goleak.IgnoreTopFunction("github.com/go-redis/redis/v7/internal/pool.(*ConnPool).reaper")
defer goleak.VerifyNoLeaks(t, ignoreOpt)
bg := NewBackground(10, &RedisConfig{
Addr: "localhost:6379",
DB: 15,
})
r := redis.NewClient(&redis.Options{
Addr: "localhost:6379",
DB: 15,
})
client := NewClient(r)
// no-op handler
h := func(task *Task) error {
return nil
}
bg.start(HandlerFunc(h))
client.Process(&Task{
Type: "send_email",
Payload: map[string]interface{}{"recipient_id": 123},
}, time.Now())
client.Process(&Task{
Type: "send_email",
Payload: map[string]interface{}{"recipient_id": 456},
}, time.Now().Add(time.Hour))
bg.stop()
}