Commit 172acae6 authored by Brad Fitzpatrick's avatar Brad Fitzpatrick

net/http: make race detector happy for recently-added test

Update #7264

Races:
http://build.golang.org/log/a2e401fdcd4903a61a3375bff5da702a20ddafad
http://build.golang.org/log/ec4c69e92076a747ac6d5df7eb7b382b31ab3d43

I think this is the first time I've actually seen a manifestation
of Issue 7264, and one that I can reproduce.

I don't know why it triggers on this test and not any others
just like it, or why I can't reproduce Issue 7264
independently, even when Dmitry gives me minimal repros.

Work around it for now with some synchronization to make the
race detector happy.

The proper fix will probably be in net/http/httptest itself, not
in all hundred some tests.

LGTM=rsc
R=rsc
CC=dvyukov, golang-codereviews
https://golang.org/cl/87640043
parent b66f863d
......@@ -2041,8 +2041,10 @@ func (f closerFunc) Close() error { return f() }
// Issue 6981
func TestTransportClosesBodyOnError(t *testing.T) {
defer afterTest(t)
readBody := make(chan error, 1)
ts := httptest.NewServer(HandlerFunc(func(w ResponseWriter, r *Request) {
ioutil.ReadAll(r.Body)
_, err := ioutil.ReadAll(r.Body)
readBody <- err
}))
defer ts.Close()
fakeErr := errors.New("fake error")
......@@ -2068,6 +2070,14 @@ func TestTransportClosesBodyOnError(t *testing.T) {
t.Fatalf("Do error = %v; want something containing %q", fakeErr.Error())
}
select {
case err := <-readBody:
if err == nil {
t.Errorf("Unexpected success reading request body from handler; want 'unexpected EOF reading trailer'")
}
case <-time.After(5 * time.Second):
t.Error("timeout waiting for server handler to complete")
}
select {
case <-didClose:
default:
t.Errorf("didn't see Body.Close")
......
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