Skip to content

Commit 922c272

Browse files
committed
fix: bugs
1 parent e86ddd3 commit 922c272

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

connstate/conn_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,19 @@ package connstate
1717
import (
1818
"errors"
1919
"net"
20+
"sync"
2021
"syscall"
2122
"testing"
2223
"time"
2324

2425
"github.com/stretchr/testify/assert"
2526
)
2627

28+
var testMutex sync.Mutex
29+
2730
func TestListenConnState(t *testing.T) {
31+
testMutex.Lock()
32+
defer testMutex.Unlock()
2833
ln, err := net.Listen("tcp", "localhost:0")
2934
if err != nil {
3035
panic(err)
@@ -88,8 +93,11 @@ func (r *mockRawConn) Control(f func(fd uintptr)) error {
8893
}
8994

9095
func TestListenConnState_Err(t *testing.T) {
96+
testMutex.Lock()
97+
defer testMutex.Unlock()
9198
var expectDetach bool
9299
pollInitOnce.Do(func() {})
100+
oldPoll := poll
93101
cases := []struct {
94102
name string
95103
connControlFunc func(f func(fd uintptr)) error
@@ -144,9 +152,16 @@ func TestListenConnState_Err(t *testing.T) {
144152
})
145153
}
146154
assert.True(t, expectDetach)
155+
if oldPoll != nil {
156+
poll = oldPoll
157+
} else {
158+
createPoller()
159+
}
147160
}
148161

149162
func BenchmarkListenConnState(b *testing.B) {
163+
testMutex.Lock()
164+
defer testMutex.Unlock()
150165
ln, err := net.Listen("tcp", "localhost:0")
151166
if err != nil {
152167
panic(err)

0 commit comments

Comments
 (0)