mirror of
https://github.com/golang/go
synced 2024-11-05 11:36:10 -07:00
net/rpc: fix a test bug
R=golang-dev, rsc CC=golang-dev https://golang.org/cl/10855043
This commit is contained in:
parent
01e1b0cb53
commit
735cf52983
@ -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) {
|
|||||||
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) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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, "")
|
||||||
|
Loading…
Reference in New Issue
Block a user