summaryrefslogtreecommitdiff
path: root/src/net
diff options
context:
space:
mode:
authorRob Pike <r@golang.org>2014-10-07 10:52:16 -0700
committerRob Pike <r@golang.org>2014-10-07 10:52:16 -0700
commit5cf79841e10a5ec2d03a32ea3a40c9932cb843eb (patch)
tree674d667da10526baf0efce152ef48b03ff31d382 /src/net
parentee50d8cf05a1e23b31dcb21c51f9bcbe529afc5a (diff)
downloadgo-5cf79841e10a5ec2d03a32ea3a40c9932cb843eb.tar.gz
net/rpc: add test for issue 7689 (gob error should cause EOF)
Helpfully supplied by tommi.virtanen in issue 8173. LGTM=rsc R=golang-codereviews, rsc CC=golang-codereviews https://codereview.appspot.com/151370043
Diffstat (limited to 'src/net')
-rw-r--r--src/net/rpc/client_test.go51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/net/rpc/client_test.go b/src/net/rpc/client_test.go
index bbfc1ec3a..c138c06b8 100644
--- a/src/net/rpc/client_test.go
+++ b/src/net/rpc/client_test.go
@@ -6,6 +6,9 @@ package rpc
import (
"errors"
+ "fmt"
+ "net"
+ "strings"
"testing"
)
@@ -34,3 +37,51 @@ func TestCloseCodec(t *testing.T) {
t.Error("client.Close did not close codec")
}
}
+
+// Test that errors in gob shut down the connection. Issue 7689.
+
+type R struct {
+ msg []byte // Not exported, so R does not work with gob.
+}
+
+type S struct{}
+
+func (s *S) Recv(nul *struct{}, reply *R) error {
+ *reply = R{[]byte("foo")}
+ return nil
+}
+
+func TestGobError(t *testing.T) {
+ defer func() {
+ err := recover()
+ if err == nil {
+ t.Fatal("no error")
+ }
+ if !strings.Contains("reading body EOF", err.(error).Error()) {
+ t.Fatal("expected `reading body EOF', got", err)
+ }
+ }()
+ Register(new(S))
+
+ listen, err := net.Listen("tcp", ":5555")
+ if err != nil {
+ panic(err)
+ }
+ go Accept(listen)
+
+ client, err := Dial("tcp", ":5555")
+ if err != nil {
+ panic(err)
+ }
+
+ var reply Reply
+ err = client.Call("S.Recv", &struct{}{}, &reply)
+ if err != nil {
+ panic(err)
+ }
+
+ fmt.Printf("%#v\n", reply)
+ client.Close()
+
+ listen.Close()
+}