mirror of
https://github.com/golang/go.git
synced 2025-11-11 14:11:04 +00:00
net: use read deadline in Accept on windows
Fixes #4296. R=golang-dev, alex.brainman CC=golang-dev https://golang.org/cl/6815044
This commit is contained in:
parent
8884fabfd7
commit
d12a7d39d1
2 changed files with 28 additions and 1 deletions
|
|
@ -119,3 +119,30 @@ func TestDeadlineReset(t *testing.T) {
|
|||
t.Errorf("unexpected return from Accept; err=%v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTimeoutAccept(t *testing.T) {
|
||||
switch runtime.GOOS {
|
||||
case "plan9":
|
||||
t.Logf("skipping test on %q", runtime.GOOS)
|
||||
return
|
||||
}
|
||||
ln, err := Listen("tcp", "127.0.0.1:0")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer ln.Close()
|
||||
tl := ln.(*TCPListener)
|
||||
tl.SetDeadline(time.Now().Add(100 * time.Millisecond))
|
||||
errc := make(chan error, 1)
|
||||
go func() {
|
||||
_, err := ln.Accept()
|
||||
errc <- err
|
||||
}()
|
||||
select {
|
||||
case <-time.After(1 * time.Second):
|
||||
// Accept shouldn't block indefinitely
|
||||
t.Errorf("Accept didn't return in an expected time")
|
||||
case <-errc:
|
||||
// Pass.
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue