mirror of
https://github.com/hibiken/asynq.git
synced 2024-12-25 23:32:17 +08:00
f3a23b9b12
This change makes it impossible to mutate payload within Handler or RetryDelayFunc.
42 lines
966 B
Go
42 lines
966 B
Go
// Copyright 2020 Kentaro Hibino. All rights reserved.
|
|
// Use of this source code is governed by a MIT license
|
|
// that can be found in the LICENSE file.
|
|
|
|
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)
|
|
|
|
r := redis.NewClient(&redis.Options{
|
|
Addr: "localhost:6379",
|
|
DB: 15,
|
|
})
|
|
client := NewClient(r)
|
|
bg := NewBackground(r, &Config{
|
|
Concurrency: 10,
|
|
})
|
|
|
|
// no-op handler
|
|
h := func(task *Task) error {
|
|
return nil
|
|
}
|
|
|
|
bg.start(HandlerFunc(h))
|
|
|
|
client.Schedule(NewTask("send_email", map[string]interface{}{"recipient_id": 123}), time.Now())
|
|
|
|
client.Schedule(NewTask("send_email", map[string]interface{}{"recipient_id": 456}), time.Now().Add(time.Hour))
|
|
|
|
bg.stop()
|
|
}
|