File tree Expand file tree Collapse file tree 1 file changed +15
-0
lines changed
Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -17,14 +17,19 @@ package connstate
1717import (
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+
2730func 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
9095func 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
149162func 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 )
You can’t perform that action at this time.
0 commit comments