Skip to content

Commit 0ccc674

Browse files
authored
chore: Goroutine leak detector to help avoid Goroutine leaks. (#7)
1 parent 8a625f8 commit 0ccc674

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ require (
66
github.com/go-redis/redis/v8 v8.11.3
77
github.com/golang-queue/queue v0.0.11
88
github.com/stretchr/testify v1.7.0
9+
go.uber.org/goleak v1.1.12
910
)

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ go.uber.org/goleak v1.1.12/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ
5757
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
5858
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
5959
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
60+
golang.org/x/lint v0.0.0-20190930215403-16217165b5de h1:5hukYrvBGR8/eNkX5mdUezrA6JiaEZDtJb9Ei+1LlBs=
6061
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
6162
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
6263
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
@@ -96,6 +97,7 @@ golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGm
9697
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
9798
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
9899
golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
100+
golang.org/x/tools v0.1.5 h1:ouewzE6p+/VEB31YYnTbEJdi8pFqKp4P4n85vwo3DHA=
99101
golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
100102
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
101103
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=

redis_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,15 @@ import (
1313
"github.com/golang-queue/queue"
1414

1515
"github.com/stretchr/testify/assert"
16+
"go.uber.org/goleak"
1617
)
1718

1819
var host = "127.0.0.1"
1920

21+
func TestMain(m *testing.M) {
22+
goleak.VerifyTestMain(m)
23+
}
24+
2025
type mockMessage struct {
2126
Message string
2227
}
@@ -327,6 +332,7 @@ func TestHandleTimeout(t *testing.T) {
327332
err := w.handle(job)
328333
assert.Error(t, err)
329334
assert.Equal(t, context.DeadlineExceeded, err)
335+
assert.NoError(t, w.Shutdown())
330336

331337
job = queue.Job{
332338
Timeout: 150 * time.Millisecond,
@@ -366,6 +372,7 @@ func TestJobComplete(t *testing.T) {
366372
err := w.handle(job)
367373
assert.Error(t, err)
368374
assert.Equal(t, errors.New("job completed"), err)
375+
assert.NoError(t, w.Shutdown())
369376

370377
job = queue.Job{
371378
Timeout: 250 * time.Millisecond,

0 commit comments

Comments
 (0)