From de899e39d51acda82c65a09cf7e5b0d58ab556ef Mon Sep 17 00:00:00 2001 From: yedf2 <120050102@qq.com> Date: Wed, 11 Aug 2021 18:38:41 +0800 Subject: [PATCH] test cover more --- dtmgrpc/type.go | 5 +++-- test/grpc_tcc_test.go | 8 ++++++++ test/grpc_xa_test.go | 8 +++++++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/dtmgrpc/type.go b/dtmgrpc/type.go index ac2aa12..e1305f3 100644 --- a/dtmgrpc/type.go +++ b/dtmgrpc/type.go @@ -16,10 +16,11 @@ var clients = map[string]*grpc.ClientConn{} // GetGrpcConn 1 func GetGrpcConn(grpcServer string) (conn *grpc.ClientConn, rerr error) { if clients[grpcServer] == nil { - conn, err := grpc.Dial(grpcServer, grpc.WithInsecure(), grpc.WithBlock(), grpc.WithUnaryInterceptor(GrpcClientLog)) + dtmcli.Logf("grpc client connecting %s", grpcServer) + conn, err := grpc.Dial(grpcServer, grpc.WithInsecure(), grpc.WithUnaryInterceptor(GrpcClientLog)) if err == nil { clients[grpcServer] = conn - dtmcli.Logf("dtm client inited for %s", grpcServer) + dtmcli.Logf("grpc client inited for %s", grpcServer) } } conn = clients[grpcServer] diff --git a/test/grpc_tcc_test.go b/test/grpc_tcc_test.go index 0b279a8..5e8348e 100644 --- a/test/grpc_tcc_test.go +++ b/test/grpc_tcc_test.go @@ -11,11 +11,19 @@ import ( ) func TestGrpcTcc(t *testing.T) { + tccGrpcType(t) tccGrpcNormal(t) tccGrpcNested(t) tccGrpcRollback(t) } +func tccGrpcType(t *testing.T) { + _, err := dtmgrpc.TccFromRequest(&dtmgrpc.BusiRequest{Info: &dtmgrpc.BranchInfo{}}) + assert.Error(t, err) + dtmcli.Logf("expecting dtmgrpcserver error") + err = dtmgrpc.TccGlobalTransaction("-", "", func(tcc *dtmgrpc.TccGrpc) error { return nil }) + assert.Error(t, err) +} func tccGrpcNormal(t *testing.T) { data := dtmcli.MustMarshal(&examples.TransReq{Amount: 30}) gid := "tccGrpcNormal" diff --git a/test/grpc_xa_test.go b/test/grpc_xa_test.go index 2b28488..5f7f2da 100644 --- a/test/grpc_xa_test.go +++ b/test/grpc_xa_test.go @@ -14,11 +14,17 @@ func TestGrpcXa(t *testing.T) { if config.DB["driver"] != "mysql" { return } - // xaGrpcLocalError(t) + xaGrpcType(t) + xaGrpcLocalError(t) xaGrpcNormal(t) xaGrpcRollback(t) } +func xaGrpcType(t *testing.T) { + _, err := dtmgrpc.XaGrpcFromRequest(&dtmgrpc.BusiRequest{Info: &dtmgrpc.BranchInfo{}}) + assert.Error(t, err) +} + func xaGrpcLocalError(t *testing.T) { xc := examples.XaGrpcClient err := xc.XaGlobalTransaction("xaGrpcLocalError", func(xa *dtmgrpc.XaGrpc) error {