Browse Source

cover nested

pull/174/head
yedf2 4 years ago
parent
commit
7c28d5acee
  1. 2
      dtmutil/utils.go
  2. 4
      test/busi/base_http.go
  3. 15
      test/tcc_cover_test.go

2
dtmutil/utils.go

@ -14,6 +14,7 @@ import (
"net/http" "net/http"
"os" "os"
"path/filepath" "path/filepath"
"reflect"
"strings" "strings"
"time" "time"
@ -64,6 +65,7 @@ func WrapHandler2(fn func(*gin.Context) interface{}) gin.HandlerFunc {
if resp, ok := r.(*resty.Response); ok { if resp, ok := r.(*resty.Response); ok {
b := resp.Body() b := resp.Body()
status = resp.StatusCode() status = resp.StatusCode()
r = nil
err = json.Unmarshal(b, &r) err = json.Unmarshal(b, &r)
} }

4
test/busi/base_http.go

@ -139,10 +139,10 @@ func BaseAddRoute(app *gin.Engine) {
}) })
})) }))
app.POST(BusiAPI+"/TransInTccParent", dtmutil.WrapHandler2(func(c *gin.Context) interface{} { app.POST(BusiAPI+"/TransInTccNested", dtmutil.WrapHandler2(func(c *gin.Context) interface{} {
tcc, err := dtmcli.TccFromQuery(c.Request.URL.Query()) tcc, err := dtmcli.TccFromQuery(c.Request.URL.Query())
logger.FatalIfError(err) logger.FatalIfError(err)
logger.Debugf("TransInTccParent ") logger.Debugf("TransInTccNested ")
resp, err := tcc.CallBranch(&TransReq{Amount: reqFrom(c).Amount}, Busi+"/TransIn", Busi+"/TransInConfirm", Busi+"/TransInRevert") resp, err := tcc.CallBranch(&TransReq{Amount: reqFrom(c).Amount}, Busi+"/TransIn", Busi+"/TransInConfirm", Busi+"/TransInRevert")
if err != nil { if err != nil {
return err return err

15
test/tcc_cover_test.go

@ -6,6 +6,7 @@ import (
"github.com/dtm-labs/dtm/dtmcli" "github.com/dtm-labs/dtm/dtmcli"
"github.com/dtm-labs/dtm/dtmcli/dtmimp" "github.com/dtm-labs/dtm/dtmcli/dtmimp"
"github.com/dtm-labs/dtm/dtmutil" "github.com/dtm-labs/dtm/dtmutil"
"github.com/dtm-labs/dtm/test/busi"
"github.com/go-resty/resty/v2" "github.com/go-resty/resty/v2"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
@ -29,3 +30,17 @@ func TestTccCoverPanic(t *testing.T) {
assert.Contains(t, err.Error(), "user panic") assert.Contains(t, err.Error(), "user panic")
waitTransProcessed(gid) waitTransProcessed(gid)
} }
func TestTccNested(t *testing.T) {
req := busi.GenTransReq(30, false, false)
gid := dtmimp.GetFuncName()
err := dtmcli.TccGlobalTransaction(dtmutil.DefaultHTTPServer, gid, func(tcc *dtmcli.Tcc) (*resty.Response, error) {
_, err := tcc.CallBranch(req, Busi+"/TransOut", Busi+"/TransOutConfirm", Busi+"/TransOutRevert")
assert.Nil(t, err)
return tcc.CallBranch(req, Busi+"/TransInTccNested", Busi+"/TransInConfirm", Busi+"/TransInRevert")
})
assert.Nil(t, err)
waitTransProcessed(gid)
assert.Equal(t, StatusSucceed, getTransStatus(gid))
assert.Equal(t, []string{StatusPrepared, StatusSucceed, StatusPrepared, StatusSucceed, StatusPrepared, StatusSucceed}, getBranchesStatus(gid))
}

Loading…
Cancel
Save