Commit 22278ca0 authored by Bryan C. Mills's avatar Bryan C. Mills

net: convert TestTCPServer to use subtests

My fix in CL 202618 inadvertently violated an invariant in the inner
loop of TestTCPServer (namely, that len(trchs) == i). That causes a
panic when one or more of the channels is omitted due to a flake.

Instead of trying to fix up the test, let's just factor out a subtest
and skip the whole thing if the transceiver's Dial flakes out.

Updates #32919

Change-Id: Ib6f274a44194311c8c5a2faf19f586cc9eccfd4d
Reviewed-on: https://go-review.googlesource.com/c/go/+/202561
Run-TryBot: Bryan C. Mills <bcmills@google.com>
Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 51504f0a
......@@ -56,79 +56,79 @@ func TestTCPServer(t *testing.T) {
const N = 3
for i, tt := range tcpServerTests {
if !testableListenArgs(tt.snet, tt.saddr, tt.taddr) {
t.Logf("skipping %s test", tt.snet+" "+tt.saddr+"<-"+tt.taddr)
continue
}
ln, err := Listen(tt.snet, tt.saddr)
if err != nil {
if perr := parseDialError(err); perr != nil {
t.Error(perr)
t.Run(tt.snet+" "+tt.saddr+"<-"+tt.taddr, func(t *testing.T) {
if !testableListenArgs(tt.snet, tt.saddr, tt.taddr) {
t.Skip("not testable")
}
t.Fatal(err)
}
var lss []*localServer
var tpchs []chan error
defer func() {
for _, ls := range lss {
ls.teardown()
}
}()
for i := 0; i < N; i++ {
ls, err := (&streamListener{Listener: ln}).newLocalServer()
ln, err := Listen(tt.snet, tt.saddr)
if err != nil {
if perr := parseDialError(err); perr != nil {
t.Error(perr)
}
t.Fatal(err)
}
lss = append(lss, ls)
tpchs = append(tpchs, make(chan error, 1))
}
for i := 0; i < N; i++ {
ch := tpchs[i]
handler := func(ls *localServer, ln Listener) { transponder(ln, ch) }
if err := lss[i].buildup(handler); err != nil {
t.Fatal(err)
}
}
var trchs []chan error
for i := 0; i < N; i++ {
_, port, err := SplitHostPort(lss[i].Listener.Addr().String())
if err != nil {
t.Fatal(err)
var lss []*localServer
var tpchs []chan error
defer func() {
for _, ls := range lss {
ls.teardown()
}
}()
for i := 0; i < N; i++ {
ls, err := (&streamListener{Listener: ln}).newLocalServer()
if err != nil {
t.Fatal(err)
}
lss = append(lss, ls)
tpchs = append(tpchs, make(chan error, 1))
}
d := Dialer{Timeout: someTimeout}
c, err := d.Dial(tt.tnet, JoinHostPort(tt.taddr, port))
if err != nil {
if perr := parseDialError(err); perr != nil {
t.Error(perr)
for i := 0; i < N; i++ {
ch := tpchs[i]
handler := func(ls *localServer, ln Listener) { transponder(ln, ch) }
if err := lss[i].buildup(handler); err != nil {
t.Fatal(err)
}
if tt.taddr == "::1" && os.Getenv("GO_BUILDER_NAME") == "darwin-amd64-10_12" && os.IsTimeout(err) {
// A suspected kernel bug in macOS 10.12 occasionally results in
// "i/o timeout" errors when dialing address ::1. The errors have not
// been observed on newer versions of the OS, so we don't plan to work
// around them. See https://golang.org/issue/32919.
t.Logf("ignoring error on known-flaky macOS 10.12 builder: %v", err)
continue
}
var trchs []chan error
for i := 0; i < N; i++ {
_, port, err := SplitHostPort(lss[i].Listener.Addr().String())
if err != nil {
t.Fatal(err)
}
t.Fatal(err)
d := Dialer{Timeout: someTimeout}
c, err := d.Dial(tt.tnet, JoinHostPort(tt.taddr, port))
if err != nil {
if perr := parseDialError(err); perr != nil {
t.Error(perr)
}
if tt.taddr == "::1" && os.Getenv("GO_BUILDER_NAME") == "darwin-amd64-10_12" && os.IsTimeout(err) {
// A suspected kernel bug in macOS 10.12 occasionally results in
// "i/o timeout" errors when dialing address ::1. The errors have not
// been observed on newer versions of the OS, so we don't plan to work
// around them. See https://golang.org/issue/32919.
t.Skipf("skipping due to error on known-flaky macOS 10.12 builder: %v", err)
}
t.Fatal(err)
}
defer c.Close()
trchs = append(trchs, make(chan error, 1))
go transceiver(c, []byte("TCP SERVER TEST"), trchs[i])
}
defer c.Close()
trchs = append(trchs, make(chan error, 1))
go transceiver(c, []byte("TCP SERVER TEST"), trchs[i])
}
for _, ch := range trchs {
for err := range ch {
t.Errorf("#%d: %v", i, err)
for _, ch := range trchs {
for err := range ch {
t.Errorf("#%d: %v", i, err)
}
}
}
for _, ch := range tpchs {
for err := range ch {
t.Errorf("#%d: %v", i, err)
for _, ch := range tpchs {
for err := range ch {
t.Errorf("#%d: %v", i, err)
}
}
}
})
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment