Commit fa32b164 authored by Dmitriy Vyukov's avatar Dmitriy Vyukov

net/rpc: fix race in TestClientWriteError test

Fixes #2752.

R=golang-dev, mpimenov, r
CC=golang-dev
https://golang.org/cl/5571062
parent 7c9ee5f3
...@@ -467,13 +467,16 @@ func TestCountMallocsOverHTTP(t *testing.T) { ...@@ -467,13 +467,16 @@ func TestCountMallocsOverHTTP(t *testing.T) {
fmt.Printf("mallocs per HTTP rpc round trip: %d\n", countMallocs(dialHTTP, 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 { func (writeCrasher) Close() error {
return nil return nil
} }
func (writeCrasher) Read(p []byte) (int, error) { func (w *writeCrasher) Read(p []byte) (int, error) {
<-w.done
return 0, io.EOF return 0, io.EOF
} }
...@@ -482,7 +485,8 @@ func (writeCrasher) Write(p []byte) (int, error) { ...@@ -482,7 +485,8 @@ func (writeCrasher) Write(p []byte) (int, error) {
} }
func TestClientWriteError(t *testing.T) { func TestClientWriteError(t *testing.T) {
c := NewClient(writeCrasher{}) w := &writeCrasher{done: make(chan bool)}
c := NewClient(w)
res := false res := false
err := c.Call("foo", 1, &res) err := c.Call("foo", 1, &res)
if err == nil { if err == nil {
...@@ -491,6 +495,7 @@ func TestClientWriteError(t *testing.T) { ...@@ -491,6 +495,7 @@ func TestClientWriteError(t *testing.T) {
if err.Error() != "fake write failure" { if err.Error() != "fake write failure" {
t.Error("unexpected value of error:", err) t.Error("unexpected value of error:", err)
} }
w.done <- true
} }
func benchmarkEndToEnd(dial func() (*Client, error), b *testing.B) { func benchmarkEndToEnd(dial func() (*Client, error), b *testing.B) {
......
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