add wait test
This commit is contained in:
parent
3a9aaa3166
commit
a170b4dd31
@ -86,9 +86,12 @@ func TransBaseFromReq(c *gin.Context) *TransBase {
|
|||||||
|
|
||||||
// CallDtm 调用dtm服务器,返回事务的状态
|
// CallDtm 调用dtm服务器,返回事务的状态
|
||||||
func (tb *TransBase) CallDtm(body interface{}, operation string) error {
|
func (tb *TransBase) CallDtm(body interface{}, operation string) error {
|
||||||
resp, err := common.RestyClient.R().SetQueryParams(common.MS{
|
params := common.MS{}
|
||||||
"wait_result": common.If(tb.WaitResult, "1", "").(string),
|
if tb.WaitResult {
|
||||||
}).SetResult(&TransResult{}).SetBody(body).Post(fmt.Sprintf("%s/%s", tb.Dtm, operation))
|
params["wait_result"] = "1"
|
||||||
|
}
|
||||||
|
resp, err := common.RestyClient.R().SetQueryParams(params).
|
||||||
|
SetResult(&TransResult{}).SetBody(body).Post(fmt.Sprintf("%s/%s", tb.Dtm, operation))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
50
dtmsvr/trans_saga_wait_test.go
Normal file
50
dtmsvr/trans_saga_wait_test.go
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
package dtmsvr
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/yedf/dtm/examples"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestSagaWait(t *testing.T) {
|
||||||
|
|
||||||
|
sagaNormalWait(t)
|
||||||
|
sagaCommittedPendingWait(t)
|
||||||
|
sagaRollbackWait(t)
|
||||||
|
}
|
||||||
|
|
||||||
|
func sagaNormalWait(t *testing.T) {
|
||||||
|
saga := genSaga("gid-noramlSagaWait", false, false)
|
||||||
|
saga.WaitResult = true
|
||||||
|
err := saga.Submit()
|
||||||
|
assert.Nil(t, err)
|
||||||
|
WaitTransProcessed(saga.Gid)
|
||||||
|
assert.Equal(t, []string{"prepared", "succeed", "prepared", "succeed"}, getBranchesStatus(saga.Gid))
|
||||||
|
assert.Equal(t, "succeed", getTransStatus(saga.Gid))
|
||||||
|
transQuery(t, saga.Gid)
|
||||||
|
}
|
||||||
|
|
||||||
|
func sagaCommittedPendingWait(t *testing.T) {
|
||||||
|
saga := genSaga("gid-committedPendingWait", false, false)
|
||||||
|
examples.MainSwitch.TransOutResult.SetOnce("PENDING")
|
||||||
|
saga.WaitResult = true
|
||||||
|
err := saga.Submit()
|
||||||
|
assert.Error(t, err)
|
||||||
|
WaitTransProcessed(saga.Gid)
|
||||||
|
assert.Equal(t, []string{"prepared", "prepared", "prepared", "prepared"}, getBranchesStatus(saga.Gid))
|
||||||
|
CronTransOnce(60 * time.Second)
|
||||||
|
assert.Equal(t, []string{"prepared", "succeed", "prepared", "succeed"}, getBranchesStatus(saga.Gid))
|
||||||
|
assert.Equal(t, "succeed", getTransStatus(saga.Gid))
|
||||||
|
}
|
||||||
|
|
||||||
|
func sagaRollbackWait(t *testing.T) {
|
||||||
|
saga := genSaga("gid-rollbackSaga2Wait", false, true)
|
||||||
|
saga.WaitResult = true
|
||||||
|
err := saga.Submit()
|
||||||
|
assert.Error(t, err)
|
||||||
|
WaitTransProcessed(saga.Gid)
|
||||||
|
assert.Equal(t, "failed", getTransStatus(saga.Gid))
|
||||||
|
assert.Equal(t, []string{"succeed", "succeed", "succeed", "failed"}, getBranchesStatus(saga.Gid))
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user