This change makes use of synchronization primitive instead of
context-based canceling not to depend on defer execution scheduling.
Fixes #17927.
Change-Id: I5ca9287a48bb5cdda6845a7f12757f95175c5db8
Reviewed-on: https://go-review.googlesource.com/33257
Reviewed-by: Ian Lance Taylor <iant@golang.org>
package net
import (
- "context"
"fmt"
"internal/testenv"
"io"
}
defer ln.Close()
- ctx, cancel := context.WithCancel(context.Background())
- defer cancel()
+ var wg sync.WaitGroup
for i, tt := range acceptTimeoutTests {
if tt.timeout < 0 {
+ wg.Add(1)
go func() {
- var d Dialer
- c, err := d.DialContext(ctx, ln.Addr().Network(), ln.Addr().String())
+ defer wg.Done()
+ d := Dialer{Timeout: 100 * time.Millisecond}
+ c, err := d.Dial(ln.Addr().Network(), ln.Addr().String())
if err != nil {
t.Error(err)
return
}
if err == nil {
c.Close()
- time.Sleep(tt.timeout / 3)
+ time.Sleep(10 * time.Millisecond)
continue
}
break
}
}
}
+ wg.Wait()
}
func TestAcceptTimeoutMustReturn(t *testing.T) {