aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAron Nopanen <aron.nopanen@gmail.com>2009-11-17 11:29:02 -0800
committerRob Pike <r@golang.org>2009-11-17 11:29:02 -0800
commitc51ee432d16ec7f0e67f2a62e457f58f86d5a708 (patch)
tree4d2ce7c5275505350a96e3ced62764a027bae7cd
parent3f00205a0a65b619f2f64818f986e83184083609 (diff)
downloadgo-c51ee432d16ec7f0e67f2a62e457f58f86d5a708.tar.gz
go-c51ee432d16ec7f0e67f2a62e457f58f86d5a708.zip
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
-rw-r--r--src/pkg/rpc/server_test.go19
1 files 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)
}