summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAron Nopanen <aron.nopanen@gmail.com>2009-11-17 11:29:02 -0800
committerAron Nopanen <aron.nopanen@gmail.com>2009-11-17 11:29:02 -0800
commit4f0f7848895208b2c16ede3a928f1c7abf84c0dd (patch)
tree3e59431e89c0d9ffc525dd8a68441ab670e7b0c1
parent45822f3abfb1d43455c02a91265cffae7327b168 (diff)
downloadgolang-4f0f7848895208b2c16ede3a928f1c7abf84c0dd.tar.gz
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 http://codereview.appspot.com/154159 Committer: Rob Pike <r@golang.org>
-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 701827b30..63a241c85 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)
}