From c51ee432d16ec7f0e67f2a62e457f58f86d5a708 Mon Sep 17 00:00:00 2001 From: Aron Nopanen Date: Tue, 17 Nov 2009 11:29:02 -0800 Subject: [PATCH] Make non-errored RPC calls return 'nil' error to caller. Error information is carried from RPC server to client in the string 'Error' field of rpc.Response. An empty string is sent in the success case. This empty string was being returned to the caller (of Client.Call or Client.Go), resulting in a non-nil error response. This change detects an empty-string Response.Error at the client, and translates it into a nil value in Call.Error. Tests updated to check error return in success cases. R=r, rsc https://golang.org/cl/154159 --- src/pkg/rpc/server_test.go | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/pkg/rpc/server_test.go b/src/pkg/rpc/server_test.go index 701827b306..63a241c85a 100644 --- a/src/pkg/rpc/server_test.go +++ b/src/pkg/rpc/server_test.go @@ -86,6 +86,9 @@ func TestRPC(t *testing.T) { args := &Args{7, 8}; reply := new(Reply); err = client.Call("Arith.Add", args, reply); + if err != nil { + t.Errorf("Add: expected no error but got string %q", err.String()) + } if reply.C != args.A+args.B { t.Errorf("Add: expected %d got %d", reply.C, args.A+args.B) } @@ -93,6 +96,9 @@ func TestRPC(t *testing.T) { args = &Args{7, 8}; reply = new(Reply); err = client.Call("Arith.Mul", args, reply); + if err != nil { + t.Errorf("Mul: expected no error but got string %q", err.String()) + } if reply.C != args.A*args.B { t.Errorf("Mul: expected %d got %d", reply.C, args.A*args.B) } @@ -104,12 +110,18 @@ func TestRPC(t *testing.T) { addReply := new(Reply); addCall := client.Go("Arith.Add", args, addReply, nil); - <-addCall.Done; + addCall = <-addCall.Done; + if addCall.Error != nil { + t.Errorf("Add: expected no error but got string %q", addCall.Error.String()) + } if addReply.C != args.A+args.B { t.Errorf("Add: expected %d got %d", addReply.C, args.A+args.B) } - <-mulCall.Done; + mulCall = <-mulCall.Done; + if mulCall.Error != nil { + t.Errorf("Mul: expected no error but got string %q", mulCall.Error.String()) + } if mulReply.C != args.A*args.B { t.Errorf("Mul: expected %d got %d", mulReply.C, args.A*args.B) } @@ -138,6 +150,9 @@ func TestHTTPRPC(t *testing.T) { args := &Args{7, 8}; reply := new(Reply); err = client.Call("Arith.Add", args, reply); + if err != nil { + t.Errorf("Add: expected no error but got string %q", err.String()) + } if reply.C != args.A+args.B { t.Errorf("Add: expected %d got %d", reply.C, args.A+args.B) } -- 2.50.0