2
0
mirror of https://github.com/hibiken/asynq.git synced 2025-10-21 21:46:12 +08:00

Add test for background to verify no goroutine leaks

This commit is contained in:
Ken Hibino
2019-11-29 20:49:18 -08:00
parent 09662432c8
commit ad1291e0a1
4 changed files with 49 additions and 0 deletions

43
background_test.go Normal file
View File

@@ -0,0 +1,43 @@
package asynq
import (
"testing"
"time"
"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, &RedisOpt{
Addr: "localhost:6379",
DB: 15,
})
client := NewClient(&RedisOpt{
Addr: "localhost:6379",
DB: 15,
})
// no-op handler
h := func(task *Task) error {
return nil
}
bg.start(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()
}