|
|
@ -11,6 +11,7 @@ import ( |
|
|
"time" |
|
|
"time" |
|
|
|
|
|
|
|
|
"github.com/dtm-labs/dtm/client/dtmcli/dtmimp" |
|
|
"github.com/dtm-labs/dtm/client/dtmcli/dtmimp" |
|
|
|
|
|
"github.com/dtm-labs/dtm/client/workflow" |
|
|
"github.com/dtm-labs/dtm/dtmsvr" |
|
|
"github.com/dtm-labs/dtm/dtmsvr" |
|
|
"github.com/dtm-labs/dtm/dtmsvr/config" |
|
|
"github.com/dtm-labs/dtm/dtmsvr/config" |
|
|
"github.com/dtm-labs/dtm/dtmutil" |
|
|
"github.com/dtm-labs/dtm/dtmutil" |
|
|
@ -39,8 +40,11 @@ func getBranchesStatus(gid string) []string { |
|
|
return status |
|
|
return status |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func isSqlStore() bool { |
|
|
|
|
|
return conf.Store.Driver == config.Mysql || conf.Store.Driver == config.Postgres |
|
|
|
|
|
} |
|
|
func TestUpdateBranchAsync(t *testing.T) { |
|
|
func TestUpdateBranchAsync(t *testing.T) { |
|
|
if conf.Store.Driver != config.Mysql { |
|
|
if !isSqlStore() { |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
conf.UpdateBranchSync = 0 |
|
|
conf.UpdateBranchSync = 0 |
|
|
@ -49,8 +53,31 @@ func TestUpdateBranchAsync(t *testing.T) { |
|
|
err := saga.Submit() |
|
|
err := saga.Submit() |
|
|
assert.Nil(t, err) |
|
|
assert.Nil(t, err) |
|
|
waitTransProcessed(saga.Gid) |
|
|
waitTransProcessed(saga.Gid) |
|
|
|
|
|
|
|
|
|
|
|
gid := dtmimp.GetFuncName() + "-wf" |
|
|
|
|
|
workflow.SetProtocolForTest(dtmimp.ProtocolHTTP) |
|
|
|
|
|
err = workflow.Register(gid, func(wf *workflow.Workflow, data []byte) error { |
|
|
|
|
|
_, err := busi.BusiCli.TransOut(wf.NewBranchCtx(), &busi.ReqGrpc{}) |
|
|
|
|
|
// add additional data directly
|
|
|
|
|
|
dtmimp.TransRegisterBranch(wf.TransBase, map[string]string{ |
|
|
|
|
|
"branch_id": "01", |
|
|
|
|
|
"op": "action", |
|
|
|
|
|
"status": "succeed", |
|
|
|
|
|
}, "registerBranch") |
|
|
|
|
|
return err |
|
|
|
|
|
}) |
|
|
|
|
|
assert.Nil(t, err) |
|
|
|
|
|
err = workflow.Execute(gid, gid, nil) |
|
|
|
|
|
assert.Nil(t, err) |
|
|
|
|
|
waitTransProcessed(gid) |
|
|
|
|
|
|
|
|
time.Sleep(dtmsvr.UpdateBranchAsyncInterval) |
|
|
time.Sleep(dtmsvr.UpdateBranchAsyncInterval) |
|
|
|
|
|
|
|
|
assert.Equal(t, []string{StatusPrepared, StatusSucceed}, getBranchesStatus(saga.Gid)) |
|
|
assert.Equal(t, []string{StatusPrepared, StatusSucceed}, getBranchesStatus(saga.Gid)) |
|
|
assert.Equal(t, StatusSucceed, getTransStatus(saga.Gid)) |
|
|
assert.Equal(t, StatusSucceed, getTransStatus(saga.Gid)) |
|
|
|
|
|
|
|
|
|
|
|
assert.Equal(t, []string{StatusSucceed}, getBranchesStatus(gid)) |
|
|
|
|
|
assert.Equal(t, StatusSucceed, getTransStatus(gid)) |
|
|
|
|
|
|
|
|
conf.UpdateBranchSync = 1 |
|
|
conf.UpdateBranchSync = 1 |
|
|
} |
|
|
} |
|
|
|