Browse Source

check more return values

pull/6/head
yedongfu 5 years ago
parent
commit
0a653d0972
  1. 2
      dtmcli/barrier.go
  2. 5
      dtmcli/message.go
  3. 3
      dtmcli/saga.go
  4. 9
      dtmcli/tcc.go
  5. 3
      dtmsvr/dtmsvr_test.go

2
dtmcli/barrier.go

@ -63,7 +63,7 @@ func insertBarrier(tx *sql.Tx, transType string, gid string, branchID string, br
if branchType == "" {
return 0, nil
}
res, err := logExec(tx, "insert into dtm_barrier.barrier(trans_type, gid, branch_id, branch_type, reason) values(?,?,?,?,?)", transType, gid, branchID, branchType, reason)
res, err := logExec(tx, "insert ignore into dtm_barrier.barrier(trans_type, gid, branch_id, branch_type, reason) values(?,?,?,?,?)", transType, gid, branchID, branchType, reason)
if err != nil {
return 0, err
}

5
dtmcli/message.go

@ -2,6 +2,7 @@ package dtmcli
import (
"fmt"
"strings"
jsonitor "github.com/json-iterator/go"
"github.com/sirupsen/logrus"
@ -57,7 +58,7 @@ func (s *Msg) Submit() error {
if err != nil {
return err
}
if resp.StatusCode() != 200 {
if !strings.Contains(resp.String(), "SUCCESS") {
return fmt.Errorf("submit failed: %v", resp.Body())
}
s.Gid = jsonitor.Get(resp.Body(), "gid").ToString()
@ -72,7 +73,7 @@ func (s *Msg) Prepare(queryPrepared string) error {
if err != nil {
return err
}
if resp.StatusCode() != 200 {
if !strings.Contains(resp.String(), "SUCCESS") {
return fmt.Errorf("prepare failed: %v", resp.Body())
}
return nil

3
dtmcli/saga.go

@ -2,6 +2,7 @@ package dtmcli
import (
"fmt"
"strings"
jsonitor "github.com/json-iterator/go"
"github.com/sirupsen/logrus"
@ -58,7 +59,7 @@ func (s *Saga) Submit() error {
if err != nil {
return err
}
if resp.StatusCode() != 200 {
if !strings.Contains(resp.String(), "SUCCESS") {
return fmt.Errorf("submit failed: %v", resp.Body())
}
s.Gid = jsonitor.Get(resp.Body(), "gid").ToString()

9
dtmcli/tcc.go

@ -2,6 +2,7 @@ package dtmcli
import (
"fmt"
"strings"
"github.com/gin-gonic/gin"
"github.com/go-resty/resty/v2"
@ -38,10 +39,13 @@ func TccGlobalTransaction(dtm string, tccFunc TccGlobalFunc) (gid string, rerr e
}
}()
tcc := &Tcc{Dtm: dtm, Gid: gid}
_, rerr = common.RestyClient.R().SetBody(data).Post(tcc.Dtm + "/prepare")
resp, rerr := common.RestyClient.R().SetBody(data).Post(tcc.Dtm + "/prepare")
if rerr != nil {
return
}
if !strings.Contains(resp.String(), "SUCCESS") {
rerr = fmt.Errorf("bad response: %s", resp.String())
}
rerr = tccFunc(tcc)
return
}
@ -77,6 +81,9 @@ func (t *Tcc) CallBranch(body interface{}, tryURL string, confirmURL string, can
if err != nil {
return resp, err
}
if !strings.Contains(resp.String(), "SUCCESS") {
return nil, fmt.Errorf("registerTccBranch failed: %s", resp.String())
}
return common.RestyClient.R().
SetBody(body).
SetQueryParams(common.MS{

3
dtmsvr/dtmsvr_test.go

@ -383,7 +383,7 @@ func tccBarrierDisorder(t *testing.T) {
go func() {
logrus.Printf("sleeping to wait for tcc try timeout")
<-timeoutChan
_, _ = common.RestyClient.R().
r, _ = common.RestyClient.R().
SetBody(body).
SetQueryParams(common.MS{
"dtm": tcc.Dtm,
@ -393,6 +393,7 @@ func tccBarrierDisorder(t *testing.T) {
"branch_type": "try",
}).
Post(tryURL)
assert.True(t, strings.Contains(r.String(), "FAILURE"))
finishedChan <- "1"
}()
logrus.Printf("cron to timeout and then call cancel")

Loading…
Cancel
Save