From 5bfdca10e96b03099b4b0cd8a562156a8d57e6f8 Mon Sep 17 00:00:00 2001 From: chenquan Date: Wed, 12 Jan 2022 08:34:31 +0800 Subject: [PATCH 1/2] chore: add goleak check. --- go.mod | 1 + go.sum | 31 ++++++ xstream/xstream_test.go | 203 +++++++++++++++++++++++++++++++++++++++- 3 files changed, 233 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index 642249c..38a5637 100644 --- a/go.mod +++ b/go.mod @@ -5,5 +5,6 @@ go 1.13 require ( github.com/panjf2000/ants/v2 v2.4.7 github.com/stretchr/testify v1.7.0 + go.uber.org/goleak v1.1.12 // indirect golang.org/x/sync v0.0.0-20210220032951-036812b2e83c ) diff --git a/go.sum b/go.sum index dffe313..a80841c 100644 --- a/go.sum +++ b/go.sum @@ -1,6 +1,9 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/panjf2000/ants/v2 v2.4.7 h1:MZnw2JRyTJxFwtaMtUJcwE618wKD04POWk2gwwP4E2M= github.com/panjf2000/ants/v2 v2.4.7/go.mod h1:f6F0NZVFsGCp5A7QW/Zj/m92atWwOkY0OIhFxRNFr4A= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= @@ -9,10 +12,38 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= +go.uber.org/goleak v1.1.12 h1:gZAh5/EyT/HQwlpkCy6wTpqfH9H8Lz8zbm3dZh+OyzA= +go.uber.org/goleak v1.1.12/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.7/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= diff --git a/xstream/xstream_test.go b/xstream/xstream_test.go index 932dc6c..857bb66 100644 --- a/xstream/xstream_test.go +++ b/xstream/xstream_test.go @@ -20,6 +20,7 @@ package xstream import ( "github.com/stretchr/testify/assert" + "go.uber.org/goleak" "reflect" "sort" "testing" @@ -41,8 +42,12 @@ func assertEqual(t *testing.T, except interface{}, data interface{}) { } } - func TestEmpty(t *testing.T) { + defer func() { + pool.Release() + goleak.VerifyNone(t, goleak.IgnoreTopFunction("github.com/panjf2000/ants/v2.(*Pool).purgePeriodically")) + }() + empty := Empty() assertEqual(t, len(empty.source), 0) assertEqual(t, cap(empty.source), 0) @@ -52,6 +57,12 @@ func TestEmpty(t *testing.T) { } func TestRange(t *testing.T) { + pool.Reboot() + defer func() { + pool.Release() + goleak.VerifyNone(t, goleak.IgnoreTopFunction("github.com/panjf2000/ants/v2.(*Pool).purgePeriodically")) + }() + stream1 := Range(make(chan interface{})) assertEqual(t, len(stream1.source), 0) @@ -61,6 +72,12 @@ func TestRange(t *testing.T) { } func TestOf(t *testing.T) { + pool.Reboot() + defer func() { + pool.Release() + goleak.VerifyNone(t, goleak.IgnoreTopFunction("github.com/panjf2000/ants/v2.(*Pool).purgePeriodically")) + }() + ints := []interface{}{1, 2, 3, 4} of := Of(ints...).Sort(func(a, b interface{}) bool { return a.(int) < b.(int) @@ -73,6 +90,12 @@ func TestOf(t *testing.T) { } func TestConcat(t *testing.T) { + pool.Reboot() + defer func() { + pool.Release() + goleak.VerifyNone(t, goleak.IgnoreTopFunction("github.com/panjf2000/ants/v2.(*Pool).purgePeriodically")) + }() + a1 := []interface{}{1, 2, 3} a2 := []interface{}{4, 5, 6} s1 := Of(a1...) @@ -96,6 +119,12 @@ func TestConcat(t *testing.T) { } func TestFrom(t *testing.T) { + pool.Reboot() + defer func() { + pool.Release() + goleak.VerifyNone(t, goleak.IgnoreTopFunction("github.com/panjf2000/ants/v2.(*Pool).purgePeriodically")) + }() + ints := make([]interface{}, 0) stream := From(func(source chan<- interface{}) { for i := 0; i < 10; i++ { @@ -111,6 +140,12 @@ func TestFrom(t *testing.T) { } func TestStream_Distinct(t *testing.T) { + pool.Reboot() + defer func() { + pool.Release() + goleak.VerifyNone(t, goleak.IgnoreTopFunction("github.com/panjf2000/ants/v2.(*Pool).purgePeriodically")) + }() + stream := Of(1, 2, 3, 4, 4, 22, 2, 1, 4).Distinct(func(item interface{}) interface{} { return item }) @@ -118,21 +153,39 @@ func TestStream_Distinct(t *testing.T) { } func TestStream_Count(t *testing.T) { + pool.Reboot() + defer func() { + pool.Release() + goleak.VerifyNone(t, goleak.IgnoreTopFunction("github.com/panjf2000/ants/v2.(*Pool).purgePeriodically")) + }() + data := []interface{}{1, 2, 3, 4, 4, 22, 2, 1, 4} assertEqual(t, Of(data...).Count(), len(data)) } func TestStream_Buffer(t *testing.T) { + pool.Reboot() + defer func() { + pool.Release() + goleak.VerifyNone(t, goleak.IgnoreTopFunction("github.com/panjf2000/ants/v2.(*Pool).purgePeriodically")) + }() + stream := Of(1, 2, 4) assertEqual(t, cap(stream.source), 3) stream = stream.Buffer(10) assertEqual(t, cap(stream.source), 10) stream = stream.Buffer(-1) assertEqual(t, cap(stream.source), 0) + stream.Done() } func TestStream_Split(t *testing.T) { + pool.Reboot() + defer func() { + pool.Release() + goleak.VerifyNone(t, goleak.IgnoreTopFunction("github.com/panjf2000/ants/v2.(*Pool).purgePeriodically")) + }() stream := Of(1, 2, 444, 441, 1).Split(3) assertEqual(t, (<-stream.source).([]interface{}), []interface{}{1, 2, 444}) @@ -146,6 +199,12 @@ func TestStream_Split(t *testing.T) { } func TestStream_SplitSteam2(t *testing.T) { + pool.Reboot() + defer func() { + pool.Release() + goleak.VerifyNone(t, goleak.IgnoreTopFunction("github.com/panjf2000/ants/v2.(*Pool).purgePeriodically")) + }() + streams := Of(1, 2, 444, 441, 1).SplitSteam(3) equal(t, (<-streams.source).(*Stream), []interface{}{1, 2, 444}) @@ -153,6 +212,12 @@ func TestStream_SplitSteam2(t *testing.T) { } func TestStream_Sort(t *testing.T) { + pool.Reboot() + defer func() { + pool.Release() + goleak.VerifyNone(t, goleak.IgnoreTopFunction("github.com/panjf2000/ants/v2.(*Pool).purgePeriodically")) + }() + ints := []interface{}{4, 2, 1, 441, 23, 14, 1, 23} stream := Of(ints...).Sort(func(a, b interface{}) bool { return a.(int) < b.(int) @@ -164,11 +229,23 @@ func TestStream_Sort(t *testing.T) { } func TestStream_Tail(t *testing.T) { + pool.Reboot() + defer func() { + pool.Release() + goleak.VerifyNone(t, goleak.IgnoreTopFunction("github.com/panjf2000/ants/v2.(*Pool).purgePeriodically")) + }() + equal(t, Of(1, 232, 3, 2, 3).Tail(1), []interface{}{3}) equal(t, Of(1, 232, 3, 2, 3).Tail(2), []interface{}{2, 3}) equal(t, Of(1, 232, 3, 2, 3).Tail(8), []interface{}{1, 232, 3, 2, 3}) } func TestTailZero(t *testing.T) { + pool.Reboot() + defer func() { + pool.Release() + goleak.VerifyNone(t, goleak.IgnoreTopFunction("github.com/panjf2000/ants/v2.(*Pool).purgePeriodically")) + }() + Of(1, 2, 3, 4).Tail(0).Done() assert.Panics(t, func() { @@ -178,6 +255,12 @@ func TestTailZero(t *testing.T) { } func TestStream_Skip(t *testing.T) { + pool.Reboot() + defer func() { + pool.Release() + goleak.VerifyNone(t, goleak.IgnoreTopFunction("github.com/panjf2000/ants/v2.(*Pool).purgePeriodically")) + }() + assertEqual(t, 3, Of(1, 2, 3, 4).Skip(1).Count()) assertEqual(t, 1, Of(1, 2, 3, 4).Skip(3).Count()) equal(t, Of(1, 2, 3, 4).Skip(3), []interface{}{4}) @@ -188,6 +271,11 @@ func TestStream_Skip(t *testing.T) { } func TestStream_Limit(t *testing.T) { + pool.Reboot() + defer func() { + pool.Release() + goleak.VerifyNone(t, goleak.IgnoreTopFunction("github.com/panjf2000/ants/v2.(*Pool).purgePeriodically")) + }() equal(t, Of(1, 2, 3, 4).Limit(3), []interface{}{1, 2, 3}) equal(t, Of(1, 2, 3, 4).Limit(4), []interface{}{1, 2, 3, 4}) @@ -200,6 +288,12 @@ func TestStream_Limit(t *testing.T) { } func TestStream_Foreach(t *testing.T) { + pool.Reboot() + defer func() { + pool.Release() + goleak.VerifyNone(t, goleak.IgnoreTopFunction("github.com/panjf2000/ants/v2.(*Pool).purgePeriodically")) + }() + var items []interface{} Of(1, 2, 3, 4).Foreach(func(item interface{}) { items = append(items, item) @@ -208,6 +302,12 @@ func TestStream_Foreach(t *testing.T) { } func TestStream_ForeachOrdered(t *testing.T) { + pool.Reboot() + defer func() { + pool.Release() + goleak.VerifyNone(t, goleak.IgnoreTopFunction("github.com/panjf2000/ants/v2.(*Pool).purgePeriodically")) + }() + var items []interface{} Of(1, 2, 3, 4).ForeachOrdered(func(item interface{}) { items = append(items, item) @@ -216,6 +316,12 @@ func TestStream_ForeachOrdered(t *testing.T) { } func TestStream_Concat(t *testing.T) { + pool.Reboot() + defer func() { + pool.Release() + goleak.VerifyNone(t, goleak.IgnoreTopFunction("github.com/panjf2000/ants/v2.(*Pool).purgePeriodically")) + }() + stream := Of(1).Concat(Of(2), Of(3)) var items []interface{} for item := range stream.source { @@ -228,6 +334,12 @@ func TestStream_Concat(t *testing.T) { } func TestStream_Filter(t *testing.T) { + pool.Reboot() + defer func() { + pool.Release() + goleak.VerifyNone(t, goleak.IgnoreTopFunction("github.com/panjf2000/ants/v2.(*Pool).purgePeriodically")) + }() + equal(t, Of(1, 2, 3, 4).Filter(func(item interface{}) bool { return item.(int) > 3 }), []interface{}{4}) @@ -239,6 +351,12 @@ func TestStream_Filter(t *testing.T) { } func TestStream_Map(t *testing.T) { + pool.Reboot() + defer func() { + pool.Release() + goleak.VerifyNone(t, goleak.IgnoreTopFunction("github.com/panjf2000/ants/v2.(*Pool).purgePeriodically")) + }() + equal(t, Of(1, 2, 3).Map(func(item interface{}) interface{} { return item.(int) + 1 }).Sort(func(a, b interface{}) bool { @@ -247,6 +365,12 @@ func TestStream_Map(t *testing.T) { } func TestStream_FlatMap(t *testing.T) { + pool.Reboot() + defer func() { + pool.Release() + goleak.VerifyNone(t, goleak.IgnoreTopFunction("github.com/panjf2000/ants/v2.(*Pool).purgePeriodically")) + }() + equal(t, Of([]interface{}{1, 2}, []interface{}{3, 4}).FlatMap(func(item interface{}) interface{} { return item @@ -266,6 +390,12 @@ func TestStream_FlatMap(t *testing.T) { } func TestStream_Group(t *testing.T) { + pool.Reboot() + defer func() { + pool.Release() + goleak.VerifyNone(t, goleak.IgnoreTopFunction("github.com/panjf2000/ants/v2.(*Pool).purgePeriodically")) + }() + equal(t, Of(1, 2, 3, 4).Group(func(item interface{}) interface{} { return item.(int) % 2 @@ -281,6 +411,12 @@ func TestStream_Group(t *testing.T) { } func TestStream_Merge(t *testing.T) { + pool.Reboot() + defer func() { + pool.Release() + goleak.VerifyNone(t, goleak.IgnoreTopFunction("github.com/panjf2000/ants/v2.(*Pool).purgePeriodically")) + }() + equal(t, Of(1, 2, 3, 4).Merge(), []interface{}{ []interface{}{1, 2, 3, 4}, @@ -288,17 +424,33 @@ func TestStream_Merge(t *testing.T) { } func TestStream_Reverse(t *testing.T) { + pool.Reboot() + defer func() { + pool.Release() + goleak.VerifyNone(t, goleak.IgnoreTopFunction("github.com/panjf2000/ants/v2.(*Pool).purgePeriodically")) + }() + equal(t, Of(1, 2, 3, 4, 1).Reverse(), []interface{}{1, 4, 3, 2, 1}) } func TestStream_ParallelFinish(t *testing.T) { - + pool.Reboot() + defer func() { + pool.Release() + goleak.VerifyNone(t, goleak.IgnoreTopFunction("github.com/panjf2000/ants/v2.(*Pool).purgePeriodically")) + }() Of(1, 23).ParallelFinish(func(item interface{}) { }, WithWorkSize(2)) } func TestStream_AnyMach(t *testing.T) { + pool.Reboot() + defer func() { + pool.Release() + goleak.VerifyNone(t, goleak.IgnoreTopFunction("github.com/panjf2000/ants/v2.(*Pool).purgePeriodically")) + }() + assertEqual(t, false, Of(1, 2, 3).AnyMach(func(item interface{}) bool { if v, ok := item.(int); ok { return v == 4 @@ -314,6 +466,12 @@ func TestStream_AnyMach(t *testing.T) { } func TestStream_AllMach(t *testing.T) { + pool.Reboot() + defer func() { + pool.Release() + goleak.VerifyNone(t, goleak.IgnoreTopFunction("github.com/panjf2000/ants/v2.(*Pool).purgePeriodically")) + }() + assertEqual( t, true, Of(1, 2, 3).AllMach(func(item interface{}) bool { return true @@ -332,6 +490,12 @@ func TestStream_AllMach(t *testing.T) { } func TestStream_Chan(t *testing.T) { + pool.Reboot() + defer func() { + pool.Release() + goleak.VerifyNone(t, goleak.IgnoreTopFunction("github.com/panjf2000/ants/v2.(*Pool).purgePeriodically")) + }() + var items []interface{} for item := range Of(1, 2, 3).Chan() { @@ -341,6 +505,12 @@ func TestStream_Chan(t *testing.T) { } func TestStream_SplitSteam(t *testing.T) { + pool.Reboot() + defer func() { + pool.Release() + goleak.VerifyNone(t, goleak.IgnoreTopFunction("github.com/panjf2000/ants/v2.(*Pool).purgePeriodically")) + }() + streams := Of(1, 2, 444, 441, 1).SplitSteam(3) equal(t, (<-streams.source).(*Stream), []interface{}{1, 2, 444}) equal(t, (<-streams.source).(*Stream), []interface{}{441, 1}) @@ -350,6 +520,12 @@ func TestStream_SplitSteam(t *testing.T) { } func TestStream_Peek(t *testing.T) { + pool.Reboot() + defer func() { + pool.Release() + goleak.VerifyNone(t, goleak.IgnoreTopFunction("github.com/panjf2000/ants/v2.(*Pool).purgePeriodically")) + }() + items := make([]interface{}, 0) Of(1, 2, 3, 4).Peek(func(item interface{}) { items = append(items, item) @@ -357,6 +533,12 @@ func TestStream_Peek(t *testing.T) { assertEqual(t, items, []interface{}{1, 2, 3, 4}) } func TestStream_FindFirst(t *testing.T) { + pool.Reboot() + defer func() { + pool.Release() + goleak.VerifyNone(t, goleak.IgnoreTopFunction("github.com/panjf2000/ants/v2.(*Pool).purgePeriodically")) + }() + result, err := Of(1, 2, 3).FindFirst() assert.NoError(t, err) assert.EqualValues(t, 1, result) @@ -367,6 +549,12 @@ func TestStream_FindFirst(t *testing.T) { } func TestStream_Copy(t *testing.T) { + pool.Reboot() + defer func() { + pool.Release() + goleak.VerifyNone(t, goleak.IgnoreTopFunction("github.com/panjf2000/ants/v2.(*Pool).purgePeriodically")) + }() + stream := Of(1, 2, 3, 4, 5) streamMap := stream.Copy(map[string]int{ "a": 1, @@ -390,6 +578,11 @@ func TestStream_Copy(t *testing.T) { } func TestStream_Collection(t *testing.T) { + pool.Reboot() + defer func() { + pool.Release() + goleak.VerifyNone(t, goleak.IgnoreTopFunction("github.com/panjf2000/ants/v2.(*Pool).purgePeriodically")) + }() t.Run("GroupBy", func(t *testing.T) { stream := Of(1, 2, 3) @@ -416,6 +609,12 @@ func TestStream_Collection(t *testing.T) { } func TestStream_FindLast(t *testing.T) { + pool.Reboot() + defer func() { + pool.Release() + goleak.VerifyNone(t, goleak.IgnoreTopFunction("github.com/panjf2000/ants/v2.(*Pool).purgePeriodically")) + }() + t.Run("has value", func(t *testing.T) { last, err := Of(1, 2, 3).FindLast() assert.NoError(t, err) From a5094900aa46b881597d37b442270ace21a6f0ae Mon Sep 17 00:00:00 2001 From: chenquan Date: Wed, 12 Jan 2022 08:35:41 +0800 Subject: [PATCH 2/2] chore: remove redundant tests --- xstream/xstream_test.go | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/xstream/xstream_test.go b/xstream/xstream_test.go index 857bb66..a639b53 100644 --- a/xstream/xstream_test.go +++ b/xstream/xstream_test.go @@ -198,19 +198,6 @@ func TestStream_Split(t *testing.T) { }) } -func TestStream_SplitSteam2(t *testing.T) { - pool.Reboot() - defer func() { - pool.Release() - goleak.VerifyNone(t, goleak.IgnoreTopFunction("github.com/panjf2000/ants/v2.(*Pool).purgePeriodically")) - }() - - streams := Of(1, 2, 444, 441, 1).SplitSteam(3) - - equal(t, (<-streams.source).(*Stream), []interface{}{1, 2, 444}) - equal(t, (<-streams.source).(*Stream), []interface{}{441, 1}) -} - func TestStream_Sort(t *testing.T) { pool.Reboot() defer func() {