[+]优雅关机

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

@@ -8,6 +8,8 @@ import (
"github.com/smallnest/rpcx/protocol"
"github.com/smallnest/rpcx/share"
"github.com/smallnest/rpcx/_testutils"
"fmt"
"time"
)
type Args struct {
@@ -27,11 +29,11 @@ func (t *Arith) Mul(ctx context.Context, args *Args, reply *Reply) error {
}
func (t *Arith) ThriftMul(ctx context.Context, args *testutils.ThriftArgs_, reply *testutils.ThriftReply) error {
reply.C = args.A * args.B
reply.C = args.A * args.B + 11111111
time.Sleep(10*time.Second)
return nil
}
func TestThrift(t *testing.T) {
s := NewServer()
s.RegisterName("Arith", new(Arith), "")
@@ -39,7 +41,30 @@ func TestThrift(t *testing.T) {
s.Register(new(Arith), "")
}
func TestGo(t *testing.T) {
go func() {
ch := make(chan int, 1)
time.Sleep(2 * time.Second)
ch <- 1
<-ch
fmt.Println("go")
}()
ch2 := make(chan struct{}, 1)
<-ch2
fmt.Println("over")
}
func TestShutdownHook(t *testing.T) {
s := NewServer()
s.ShutdownFunc = func(s *Server) {
ctx, _ := context.WithTimeout(context.Background(), 155*time.Second)
s.Shutdown(ctx)
}
s.RegisterName("Arith", new(Arith), "")
s.Serve("tcp", ":8995")
s.Register(new(Arith), "")
}
func TestHandleRequest(t *testing.T) {
//use jsoncodec