test cover more

This commit is contained in:
yedf2 2021-08-11 18:38:41 +08:00
parent a12f3c9529
commit de899e39d5
3 changed files with 18 additions and 3 deletions

View File

@ -16,10 +16,11 @@ var clients = map[string]*grpc.ClientConn{}
// GetGrpcConn 1 // GetGrpcConn 1
func GetGrpcConn(grpcServer string) (conn *grpc.ClientConn, rerr error) { func GetGrpcConn(grpcServer string) (conn *grpc.ClientConn, rerr error) {
if clients[grpcServer] == nil { 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 { if err == nil {
clients[grpcServer] = conn clients[grpcServer] = conn
dtmcli.Logf("dtm client inited for %s", grpcServer) dtmcli.Logf("grpc client inited for %s", grpcServer)
} }
} }
conn = clients[grpcServer] conn = clients[grpcServer]

View File

@ -11,11 +11,19 @@ import (
) )
func TestGrpcTcc(t *testing.T) { func TestGrpcTcc(t *testing.T) {
tccGrpcType(t)
tccGrpcNormal(t) tccGrpcNormal(t)
tccGrpcNested(t) tccGrpcNested(t)
tccGrpcRollback(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) { func tccGrpcNormal(t *testing.T) {
data := dtmcli.MustMarshal(&examples.TransReq{Amount: 30}) data := dtmcli.MustMarshal(&examples.TransReq{Amount: 30})
gid := "tccGrpcNormal" gid := "tccGrpcNormal"

View File

@ -14,11 +14,17 @@ func TestGrpcXa(t *testing.T) {
if config.DB["driver"] != "mysql" { if config.DB["driver"] != "mysql" {
return return
} }
// xaGrpcLocalError(t) xaGrpcType(t)
xaGrpcLocalError(t)
xaGrpcNormal(t) xaGrpcNormal(t)
xaGrpcRollback(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) { func xaGrpcLocalError(t *testing.T) {
xc := examples.XaGrpcClient xc := examples.XaGrpcClient
err := xc.XaGlobalTransaction("xaGrpcLocalError", func(xa *dtmgrpc.XaGrpc) error { err := xc.XaGlobalTransaction("xaGrpcLocalError", func(xa *dtmgrpc.XaGrpc) error {