Commit 735cf529 authored by ChaiShushan's avatar ChaiShushan Committed by Russ Cox

net/rpc: fix a test bug

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/10855043
parent 01e1b0cb
...@@ -99,11 +99,12 @@ func startNewServer() { ...@@ -99,11 +99,12 @@ func startNewServer() {
newServer = NewServer() newServer = NewServer()
newServer.Register(new(Arith)) newServer.Register(new(Arith))
newServer.RegisterName("net.rpc.Arith", new(Arith)) newServer.RegisterName("net.rpc.Arith", new(Arith))
newServer.RegisterName("newServer.Arith", new(Arith))
var l net.Listener var l net.Listener
l, newServerAddr = listenTCP() l, newServerAddr = listenTCP()
log.Println("NewServer test RPC server listening on", newServerAddr) log.Println("NewServer test RPC server listening on", newServerAddr)
go Accept(l) go newServer.Accept(l)
newServer.HandleHTTP(newHttpPath, "/bar") newServer.HandleHTTP(newHttpPath, "/bar")
httpOnce.Do(startHttpServer) httpOnce.Do(startHttpServer)
...@@ -120,6 +121,7 @@ func TestRPC(t *testing.T) { ...@@ -120,6 +121,7 @@ func TestRPC(t *testing.T) {
testRPC(t, serverAddr) testRPC(t, serverAddr)
newOnce.Do(startNewServer) newOnce.Do(startNewServer)
testRPC(t, newServerAddr) testRPC(t, newServerAddr)
testNewServerRPC(t, newServerAddr)
} }
func testRPC(t *testing.T, addr string) { func testRPC(t *testing.T, addr string) {
...@@ -249,6 +251,25 @@ func testRPC(t *testing.T, addr string) { ...@@ -249,6 +251,25 @@ func testRPC(t *testing.T, addr string) {
} }
} }
func testNewServerRPC(t *testing.T, addr string) {
client, err := Dial("tcp", addr)
if err != nil {
t.Fatal("dialing", err)
}
defer client.Close()
// Synchronous calls
args := &Args{7, 8}
reply := new(Reply)
err = client.Call("newServer.Arith.Add", args, reply)
if err != nil {
t.Errorf("Add: expected no error but got string %q", err.Error())
}
if reply.C != args.A+args.B {
t.Errorf("Add: expected %d got %d", reply.C, args.A+args.B)
}
}
func TestHTTP(t *testing.T) { func TestHTTP(t *testing.T) {
once.Do(startServer) once.Do(startServer)
testHTTPRPC(t, "") testHTTPRPC(t, "")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment