Skip to content

Commit 629c05e

Browse files
authored
Merge pull request #706 from panjf2000/dev
minor: v2.8.0
2 parents 2776c3d + 301a85e commit 629c05e

File tree

5 files changed

+22
-15
lines changed

5 files changed

+22
-15
lines changed

conn_matrix_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"net"
77
"testing"
88

9+
"github.com/stretchr/testify/require"
910
"golang.org/x/sys/unix"
1011

1112
goPool "github.com/panjf2000/gnet/v2/pkg/pool/goroutine"
@@ -51,7 +52,7 @@ func testConnMatrix(t *testing.T, n int) {
5152
el := eventloop{engine: &engine{opts: &Options{}}}
5253

5354
done := make(chan struct{})
54-
go func() {
55+
err := goPool.DefaultWorkerPool.Submit(func() {
5556
for i := 0; i < n+n/2; i++ {
5657
v := <-handleConns
5758
switch v.action {
@@ -62,14 +63,14 @@ func testConnMatrix(t *testing.T, n int) {
6263
}
6364
}
6465
close(done)
65-
}()
66+
})
67+
require.NoError(t, err)
6668

67-
pool := goPool.Default()
6869
for i := 0; i < n; i++ {
6970
c := newTCPConn(i, &el, &unix.SockaddrInet4{}, &net.TCPAddr{}, &net.TCPAddr{})
7071
handleConns <- &handleConn{c, actionAdd}
7172
if i%2 == 0 {
72-
pool.Submit(func() {
73+
_ = goPool.DefaultWorkerPool.Submit(func() {
7374
handleConns <- &handleConn{c, actionDel}
7475
})
7576
}

eventloop_unix_test.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import (
1414
"golang.org/x/sys/unix"
1515

1616
"github.com/stretchr/testify/assert"
17+
18+
goPool "github.com/panjf2000/gnet/v2/pkg/pool/goroutine"
1719
)
1820

1921
func (lb *roundRobinLoadBalancer) register(el *eventloop) {
@@ -98,7 +100,7 @@ func benchServeGC(b *testing.B, network, addr string, async bool, elNum int, ini
98100
}
99101

100102
nowEventLoopInitConn = initConnCount
101-
go func() {
103+
_ = goPool.DefaultWorkerPool.Submit(func() {
102104
err := Run(ts,
103105
network+"://"+addr,
104106
WithLockOSThread(async),
@@ -107,7 +109,7 @@ func benchServeGC(b *testing.B, network, addr string, async bool, elNum int, ini
107109
WithTCPNoDelay(TCPDelay))
108110
assert.NoError(b, err)
109111
nowEventLoopInitConn = 0
110-
}()
112+
})
111113
<-ts.initOk
112114
return ts
113115
}
@@ -126,12 +128,12 @@ type benchmarkServerGC struct {
126128

127129
func (s *benchmarkServerGC) OnBoot(eng Engine) (action Action) {
128130
s.eng = eng
129-
go func() {
131+
_ = goPool.DefaultWorkerPool.Submit(func() {
130132
for s.eng.eng.eventLoops.len() != s.elNum || s.eng.CountConnections() != s.elNum*int(s.initConnCount) {
131133
time.Sleep(time.Millisecond)
132134
}
133135
close(s.initOk)
134-
}()
136+
})
135137
return
136138
}
137139

@@ -253,7 +255,10 @@ func (s *testServerGC) OnBoot(eng Engine) (action Action) {
253255
if testBigGC {
254256
gcSecs = 10
255257
}
256-
go s.GC(gcSecs)
258+
err := goPool.DefaultWorkerPool.Submit(func() {
259+
s.GC(gcSecs)
260+
})
261+
assert.NoError(s.tester, err)
257262

258263
return
259264
}

go.mod

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module github.com/panjf2000/gnet/v2
22

33
require (
4-
github.com/panjf2000/ants/v2 v2.11.0
4+
github.com/panjf2000/ants/v2 v2.11.3
55
github.com/stretchr/testify v1.10.0
66
github.com/valyala/bytebufferpool v1.0.0
77
go.uber.org/zap v1.27.0
@@ -18,4 +18,3 @@ require (
1818
)
1919

2020
go 1.20
21-

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
22
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3-
github.com/panjf2000/ants/v2 v2.11.0 h1:sHrqEwTBQTQ2w6PMvbMfvBtVUuhsaYPzUmAYDLYmJPg=
4-
github.com/panjf2000/ants/v2 v2.11.0/go.mod h1:V9HhTupTWxcaRmIglJvGwvzqXUTnIZW9uO6q4hAfApw=
3+
github.com/panjf2000/ants/v2 v2.11.3 h1:AfI0ngBoXJmYOpDh9m516vjqoUu2sLrIVgppI9TZVpg=
4+
github.com/panjf2000/ants/v2 v2.11.3/go.mod h1:8u92CYMUc6gyvTIw8Ru7Mt7+/ESnJahz5EVtqfrilek=
55
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
66
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
77
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=

os_unix_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222

2323
errorx "github.com/panjf2000/gnet/v2/pkg/errors"
2424
"github.com/panjf2000/gnet/v2/pkg/logging"
25+
goPool "github.com/panjf2000/gnet/v2/pkg/pool/goroutine"
2526
)
2627

2728
var (
@@ -150,10 +151,11 @@ func (s *testMcastServer) OnTick() (delay time.Duration, action Action) {
150151
if atomic.CompareAndSwapInt32(&s.started, 0, 1) {
151152
for i := 0; i < s.nclients; i++ {
152153
atomic.AddInt32(&s.active, 1)
153-
go func() {
154+
err := goPool.DefaultWorkerPool.Submit(func() {
154155
defer atomic.AddInt32(&s.active, -1)
155156
s.startMcastClient()
156-
}()
157+
})
158+
assert.NoError(s.t, err)
157159
}
158160
}
159161
if atomic.LoadInt32(&s.active) == 0 {

0 commit comments

Comments
 (0)