1 // Copyright 2016 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 // +build !js,!plan9,!windows
19 // See golang.org/issue/14548.
20 func TestTCPSpuriousConnSetupCompletion(t
*testing
.T
) {
22 t
.Skip("skipping in short mode")
25 ln
, err
:= newLocalListener("tcp")
31 go func(ln Listener
) {
48 attempts
:= int(1e4
) // larger is better
50 throttle
:= make(chan struct{}, runtime
.GOMAXPROCS(-1)*2)
51 for i
:= 0; i
< attempts
; i
++ {
52 throttle
<- struct{}{}
58 d
:= Dialer
{Timeout
: 50 * time
.Millisecond
}
59 c
, err
:= d
.Dial(ln
.Addr().Network(), ln
.Addr().String())
61 if perr
:= parseDialError(err
); perr
!= nil {
62 t
.Errorf("#%d: %v (original error: %v)", i
, perr
, err
)
67 if _
, err
:= c
.Write(b
[:]); err
!= nil {
68 if perr
:= parseWriteError(err
); perr
!= nil {
69 t
.Errorf("#%d: %v", i
, err
)
71 if samePlatformError(err
, syscall
.ENOTCONN
) {
72 t
.Errorf("#%d: %v", i
, err
)
84 // Test that a canceled Dial does not cause a subsequent Dial to succeed.
85 func TestTCPSpuriousConnSetupCompletionWithCancel(t
*testing
.T
) {
86 mustHaveExternalNetwork(t
)
88 defer dnsWaitGroup
.Wait()
93 sem
:= make(chan bool, 5)
94 for i
:= 0; i
< tries
; i
++ {
96 ctx
, cancel
:= context
.WithCancel(context
.Background())
99 time
.Sleep(time
.Duration(rand
.Int63n(int64(5 * time
.Millisecond
))))
105 // Try to connect to a real host on a port
106 // that it is not listening on.
107 _
, err
:= dialer
.DialContext(ctx
, "tcp", "golang.org:3")
109 t
.Errorf("Dial to unbound port succeeded on attempt %d", i
)