Commit b78aaec2 authored by ChaiShushan's avatar ChaiShushan Committed by Rob Pike

net/rpc: call client.Close() when test exit

Fixes #5768.

R=golang-dev
CC=golang-dev
https://golang.org/cl/10503043
parent 6db28ee8
...@@ -125,6 +125,7 @@ func testRPC(t *testing.T, addr string) { ...@@ -125,6 +125,7 @@ func testRPC(t *testing.T, addr string) {
if err != nil { if err != nil {
t.Fatal("dialing", err) t.Fatal("dialing", err)
} }
defer client.Close()
// Synchronous calls // Synchronous calls
args := &Args{7, 8} args := &Args{7, 8}
...@@ -253,6 +254,7 @@ func testHTTPRPC(t *testing.T, path string) { ...@@ -253,6 +254,7 @@ func testHTTPRPC(t *testing.T, path string) {
if err != nil { if err != nil {
t.Fatal("dialing", err) t.Fatal("dialing", err)
} }
defer client.Close()
// Synchronous calls // Synchronous calls
args := &Args{7, 8} args := &Args{7, 8}
...@@ -329,6 +331,7 @@ func TestServeRequest(t *testing.T) { ...@@ -329,6 +331,7 @@ func TestServeRequest(t *testing.T) {
func testServeRequest(t *testing.T, server *Server) { func testServeRequest(t *testing.T, server *Server) {
client := CodecEmulator{server: server} client := CodecEmulator{server: server}
defer client.Close()
args := &Args{7, 8} args := &Args{7, 8}
reply := new(Reply) reply := new(Reply)
...@@ -411,6 +414,7 @@ func (WriteFailCodec) Close() error { ...@@ -411,6 +414,7 @@ func (WriteFailCodec) Close() error {
func TestSendDeadlock(t *testing.T) { func TestSendDeadlock(t *testing.T) {
client := NewClientWithCodec(WriteFailCodec(0)) client := NewClientWithCodec(WriteFailCodec(0))
defer client.Close()
done := make(chan bool) done := make(chan bool)
go func() { go func() {
...@@ -449,6 +453,8 @@ func countMallocs(dial func() (*Client, error), t *testing.T) float64 { ...@@ -449,6 +453,8 @@ func countMallocs(dial func() (*Client, error), t *testing.T) float64 {
if err != nil { if err != nil {
t.Fatal("error dialing", err) t.Fatal("error dialing", err)
} }
defer client.Close()
args := &Args{7, 8} args := &Args{7, 8}
reply := new(Reply) reply := new(Reply)
return testing.AllocsPerRun(100, func() { return testing.AllocsPerRun(100, func() {
...@@ -496,6 +502,8 @@ func (writeCrasher) Write(p []byte) (int, error) { ...@@ -496,6 +502,8 @@ func (writeCrasher) Write(p []byte) (int, error) {
func TestClientWriteError(t *testing.T) { func TestClientWriteError(t *testing.T) {
w := &writeCrasher{done: make(chan bool)} w := &writeCrasher{done: make(chan bool)}
c := NewClient(w) c := NewClient(w)
defer c.Close()
res := false res := false
err := c.Call("foo", 1, &res) err := c.Call("foo", 1, &res)
if err == nil { if err == nil {
...@@ -552,6 +560,7 @@ func benchmarkEndToEnd(dial func() (*Client, error), b *testing.B) { ...@@ -552,6 +560,7 @@ func benchmarkEndToEnd(dial func() (*Client, error), b *testing.B) {
if err != nil { if err != nil {
b.Fatal("error dialing:", err) b.Fatal("error dialing:", err)
} }
defer client.Close()
// Synchronous calls // Synchronous calls
args := &Args{7, 8} args := &Args{7, 8}
...@@ -587,6 +596,7 @@ func benchmarkEndToEndAsync(dial func() (*Client, error), b *testing.B) { ...@@ -587,6 +596,7 @@ func benchmarkEndToEndAsync(dial func() (*Client, error), b *testing.B) {
if err != nil { if err != nil {
b.Fatal("error dialing:", err) b.Fatal("error dialing:", err)
} }
defer client.Close()
// Asynchronous calls // Asynchronous calls
args := &Args{7, 8} args := &Args{7, 8}
......
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