File tree Expand file tree Collapse file tree 2 files changed +12
-8
lines changed Expand file tree Collapse file tree 2 files changed +12
-8
lines changed Original file line number Diff line number Diff line change @@ -95,9 +95,17 @@ func (r *mockRawConn) Control(f func(fd uintptr)) error {
9595func TestListenConnState_Err (t * testing.T ) {
9696 testMutex .Lock ()
9797 defer testMutex .Unlock ()
98- var expectDetach bool
99- pollInitOnce .Do (func () {} )
98+ // replace poll
99+ pollInitOnce .Do (createPoller )
100100 oldPoll := poll
101+ defer func () {
102+ poll = oldPoll
103+ }()
104+ // test detach
105+ var expectDetach bool
106+ defer func () {
107+ assert .True (t , expectDetach )
108+ }()
101109 cases := []struct {
102110 name string
103111 connControlFunc func (f func (fd uintptr )) error
@@ -151,12 +159,6 @@ func TestListenConnState_Err(t *testing.T) {
151159 assert .Equal (t , c .expectErr , err )
152160 })
153161 }
154- assert .True (t , expectDetach )
155- if oldPoll != nil {
156- poll = oldPoll
157- } else {
158- createPoller ()
159- }
160162}
161163
162164func BenchmarkListenConnState (b * testing.B ) {
Original file line number Diff line number Diff line change @@ -32,6 +32,8 @@ type epoller struct {
3232func (p * epoller ) wait () error {
3333 events := make ([]syscall.EpollEvent , 1024 )
3434 for {
35+ // epoll wait is a blocking syscall, so we need to call entersyscallblock to handoff P,
36+ // and let the P run other goroutines.
3537 n , err := isyscall .EpollWait (p .epfd , events , - 1 )
3638 if err != nil && err != syscall .EINTR {
3739 return err
You can’t perform that action at this time.
0 commit comments