From fa32b1641312f46b57ed8dbfdc83e0f726334a6a Mon Sep 17 00:00:00 2001 From: Dmitriy Vyukov Date: Thu, 26 Jan 2012 11:37:07 +0400 Subject: [PATCH] net/rpc: fix race in TestClientWriteError test Fixes #2752. R=golang-dev, mpimenov, r CC=golang-dev https://golang.org/cl/5571062 --- src/pkg/net/rpc/server_test.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/pkg/net/rpc/server_test.go b/src/pkg/net/rpc/server_test.go index ae688c0f8ca..7536c6dd6f5 100644 --- a/src/pkg/net/rpc/server_test.go +++ b/src/pkg/net/rpc/server_test.go @@ -467,13 +467,16 @@ func TestCountMallocsOverHTTP(t *testing.T) { fmt.Printf("mallocs per HTTP rpc round trip: %d\n", countMallocs(dialHTTP, t)) } -type writeCrasher struct{} +type writeCrasher struct { + done chan bool +} func (writeCrasher) Close() error { return nil } -func (writeCrasher) Read(p []byte) (int, error) { +func (w *writeCrasher) Read(p []byte) (int, error) { + <-w.done return 0, io.EOF } @@ -482,7 +485,8 @@ func (writeCrasher) Write(p []byte) (int, error) { } func TestClientWriteError(t *testing.T) { - c := NewClient(writeCrasher{}) + w := &writeCrasher{done: make(chan bool)} + c := NewClient(w) res := false err := c.Call("foo", 1, &res) if err == nil { @@ -491,6 +495,7 @@ func TestClientWriteError(t *testing.T) { if err.Error() != "fake write failure" { t.Error("unexpected value of error:", err) } + w.done <- true } func benchmarkEndToEnd(dial func() (*Client, error), b *testing.B) {