[+]优雅关机

This commit is contained in:
goodjava@qq.com
2018-06-29 10:15:20 +08:00
parent 6d27d83a46
commit d2ad510535
6 changed files with 535 additions and 57 deletions

View File

@@ -9,12 +9,44 @@ import (
"github.com/smallnest/rpcx/share"
"github.com/smallnest/rpcx/protocol"
"github.com/smallnest/rpcx/_testutils"
"fmt"
)
func TestLoop(t *testing.T) {
opt := Option{
Retries: 1,
RPCPath: share.DefaultRPCPath,
ConnectTimeout: 10 * time.Second,
SerializeType: protocol.Thrift,
CompressType: protocol.None,
BackupLatency: 10 * time.Millisecond,
}
d := NewPeer2PeerDiscovery("tcp@127.0.0.1:8995", "desc=a test service")
xclient := NewXClient("Arith", Failtry, RandomSelect, d, opt)
defer xclient.Close()
tick := time.NewTicker(2*time.Second)
for ti := range tick.C {
fmt.Println(ti)
args := testutils.ThriftArgs_{}
args.A = 200
args.B = 100
go func(){
reply := testutils.ThriftReply{}
err := xclient.Call(context.Background(), "ThriftMul", &args, &reply)
fmt.Println(reply.C,err)
}()
}
}
func TestXClient_Thrift(t *testing.T) {
opt := Option{
Retries: 3,
Retries: 1,
RPCPath: share.DefaultRPCPath,
ConnectTimeout: 10 * time.Second,
SerializeType: protocol.Thrift,
@@ -38,6 +70,7 @@ func TestXClient_Thrift(t *testing.T) {
t.Fatalf("failed to call: %v", err)
}
fmt.Println(reply.C)
if reply.C != 20000 {
t.Fatalf("expect 20000 but got %d", reply.C)
}