check more return values
This commit is contained in:
parent
73d5fe8690
commit
0a653d0972
@ -63,7 +63,7 @@ func insertBarrier(tx *sql.Tx, transType string, gid string, branchID string, br
|
|||||||
if branchType == "" {
|
if branchType == "" {
|
||||||
return 0, nil
|
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 {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,6 +2,7 @@ package dtmcli
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
jsonitor "github.com/json-iterator/go"
|
jsonitor "github.com/json-iterator/go"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
@ -57,7 +58,7 @@ func (s *Msg) Submit() error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if resp.StatusCode() != 200 {
|
if !strings.Contains(resp.String(), "SUCCESS") {
|
||||||
return fmt.Errorf("submit failed: %v", resp.Body())
|
return fmt.Errorf("submit failed: %v", resp.Body())
|
||||||
}
|
}
|
||||||
s.Gid = jsonitor.Get(resp.Body(), "gid").ToString()
|
s.Gid = jsonitor.Get(resp.Body(), "gid").ToString()
|
||||||
@ -72,7 +73,7 @@ func (s *Msg) Prepare(queryPrepared string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if resp.StatusCode() != 200 {
|
if !strings.Contains(resp.String(), "SUCCESS") {
|
||||||
return fmt.Errorf("prepare failed: %v", resp.Body())
|
return fmt.Errorf("prepare failed: %v", resp.Body())
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@ -2,6 +2,7 @@ package dtmcli
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
jsonitor "github.com/json-iterator/go"
|
jsonitor "github.com/json-iterator/go"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
@ -58,7 +59,7 @@ func (s *Saga) Submit() error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if resp.StatusCode() != 200 {
|
if !strings.Contains(resp.String(), "SUCCESS") {
|
||||||
return fmt.Errorf("submit failed: %v", resp.Body())
|
return fmt.Errorf("submit failed: %v", resp.Body())
|
||||||
}
|
}
|
||||||
s.Gid = jsonitor.Get(resp.Body(), "gid").ToString()
|
s.Gid = jsonitor.Get(resp.Body(), "gid").ToString()
|
||||||
|
|||||||
@ -2,6 +2,7 @@ package dtmcli
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/go-resty/resty/v2"
|
"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}
|
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 {
|
if rerr != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if !strings.Contains(resp.String(), "SUCCESS") {
|
||||||
|
rerr = fmt.Errorf("bad response: %s", resp.String())
|
||||||
|
}
|
||||||
rerr = tccFunc(tcc)
|
rerr = tccFunc(tcc)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -77,6 +81,9 @@ func (t *Tcc) CallBranch(body interface{}, tryURL string, confirmURL string, can
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return resp, err
|
return resp, err
|
||||||
}
|
}
|
||||||
|
if !strings.Contains(resp.String(), "SUCCESS") {
|
||||||
|
return nil, fmt.Errorf("registerTccBranch failed: %s", resp.String())
|
||||||
|
}
|
||||||
return common.RestyClient.R().
|
return common.RestyClient.R().
|
||||||
SetBody(body).
|
SetBody(body).
|
||||||
SetQueryParams(common.MS{
|
SetQueryParams(common.MS{
|
||||||
|
|||||||
@ -383,7 +383,7 @@ func tccBarrierDisorder(t *testing.T) {
|
|||||||
go func() {
|
go func() {
|
||||||
logrus.Printf("sleeping to wait for tcc try timeout")
|
logrus.Printf("sleeping to wait for tcc try timeout")
|
||||||
<-timeoutChan
|
<-timeoutChan
|
||||||
_, _ = common.RestyClient.R().
|
r, _ = common.RestyClient.R().
|
||||||
SetBody(body).
|
SetBody(body).
|
||||||
SetQueryParams(common.MS{
|
SetQueryParams(common.MS{
|
||||||
"dtm": tcc.Dtm,
|
"dtm": tcc.Dtm,
|
||||||
@ -393,6 +393,7 @@ func tccBarrierDisorder(t *testing.T) {
|
|||||||
"branch_type": "try",
|
"branch_type": "try",
|
||||||
}).
|
}).
|
||||||
Post(tryURL)
|
Post(tryURL)
|
||||||
|
assert.True(t, strings.Contains(r.String(), "FAILURE"))
|
||||||
finishedChan <- "1"
|
finishedChan <- "1"
|
||||||
}()
|
}()
|
||||||
logrus.Printf("cron to timeout and then call cancel")
|
logrus.Printf("cron to timeout and then call cancel")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user