mirror of
https://github.com/smallnest/rpcx.git
synced 2025-10-15 12:42:16 +08:00
[+]优雅关机
This commit is contained in:
@@ -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
|
||||
|
Reference in New Issue
Block a user