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 //go:build !plan9 && !windows
19 // See golang.org/issue/14548.
20 func TestTCPSpuriousConnSetupCompletion(t *testing.T) {
22 t.Skip("skipping in short mode")
25 ln := newLocalListener(t, "tcp")
28 go func(ln Listener) {
45 attempts := int(1e4) // larger is better
47 throttle := make(chan struct{}, runtime.GOMAXPROCS(-1)*2)
48 for i := 0; i < attempts; i++ {
49 throttle <- struct{}{}
55 d := Dialer{Timeout: 50 * time.Millisecond}
56 c, err := d.Dial(ln.Addr().Network(), ln.Addr().String())
58 if perr := parseDialError(err); perr != nil {
59 t.Errorf("#%d: %v (original error: %v)", i, perr, err)
64 if _, err := c.Write(b[:]); err != nil {
65 if perr := parseWriteError(err); perr != nil {
66 t.Errorf("#%d: %v", i, err)
68 if samePlatformError(err, syscall.ENOTCONN) {
69 t.Errorf("#%d: %v", i, err)
81 // Test that a canceled Dial does not cause a subsequent Dial to succeed.
82 func TestTCPSpuriousConnSetupCompletionWithCancel(t *testing.T) {
83 mustHaveExternalNetwork(t)
85 defer dnsWaitGroup.Wait()
90 sem := make(chan bool, 5)
91 for i := 0; i < tries; i++ {
93 ctx, cancel := context.WithCancel(context.Background())
96 time.Sleep(time.Duration(rand.Int63n(int64(5 * time.Millisecond))))
102 // Try to connect to a real host on a port
103 // that it is not listening on.
104 _, err := dialer.DialContext(ctx, "tcp", "golang.org:3")
106 t.Errorf("Dial to unbound port succeeded on attempt %d", i)