1
0
mirror of https://github.com/golang/go synced 2024-11-23 16:20:04 -07:00

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
This commit is contained in:
Brad Fitzpatrick 2014-04-14 12:08:32 -07:00
parent b66f863dc4
commit 172acae68a

View File

@ -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")