Skip to content

Commit

Permalink
osutil/epoll: make TestEpollWaitEintrHandling -race clean
Browse files Browse the repository at this point in the history
  • Loading branch information
pedronis committed Sep 8, 2023
1 parent 90d9d4a commit 69f1a5f
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions osutil/epoll/epoll_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package epoll_test

import (
"os"
"sync"
"syscall"
"testing"
"time"
Expand Down Expand Up @@ -204,12 +205,26 @@ func (*epollSuite) TestEpollWaitEintrHandling(c *C) {
c.Assert(err, IsNil)
c.Assert(e.RegisteredFdCount(), Equals, 1)

mockReturnedN := 0
mockReturnedErr := unix.EINTR
var mu sync.Mutex
eintr := true
doReturnEintr := func() bool {
mu.Lock()
defer mu.Unlock()
return eintr
}
stopEintr := func() {
mu.Lock()
defer mu.Unlock()
eintr = false
}
restore := epoll.MockUnixEpollWait(func(epfd int, events []unix.EpollEvent, msec int) (n int, err error) {
time.Sleep(time.Millisecond * 10) // rate limit a bit
return mockReturnedN, mockReturnedErr
if doReturnEintr() {
time.Sleep(time.Millisecond * 10) // rate limit a bit
return 0, unix.EINTR
}
return unix.EpollWait(epfd, events, msec)
})
defer restore()

eventCh := make(chan []epoll.Event)
errCh := make(chan error)
Expand All @@ -226,7 +241,7 @@ func (*epollSuite) TestEpollWaitEintrHandling(c *C) {

startTime := time.Now()

time.AfterFunc(defaultDuration, restore)
time.AfterFunc(defaultDuration, stopEintr)

events = <-eventCh
err = <-errCh
Expand Down

0 comments on commit 69f1a5f

Please sign in to comment.