1
0
mirror of https://github.com/golang/go synced 2024-10-03 06:11:21 -06:00

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
This commit is contained in:
Aron Nopanen 2009-11-17 11:29:02 -08:00 committed by Rob Pike
parent 3f00205a0a
commit c51ee432d1

View File

@ -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)
}