-
Notifications
You must be signed in to change notification settings - Fork 980
/
Copy pathxa_cover_test.go
54 lines (49 loc) · 1.59 KB
/
xa_cover_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package test
import (
"testing"
"github.com/dtm-labs/dtm/client/dtmcli"
"github.com/dtm-labs/dtm/client/dtmcli/dtmimp"
"github.com/dtm-labs/dtm/test/busi"
"github.com/go-resty/resty/v2"
"github.com/stretchr/testify/assert"
)
func TestXaCoverDBError(t *testing.T) {
oldDriver := busi.BusiConf.Driver
gid := dtmimp.GetFuncName()
err := dtmcli.XaGlobalTransaction(DtmServer, gid, func(xa *dtmcli.Xa) (*resty.Response, error) {
req := busi.GenReqHTTP(30, false, false)
_, err := xa.CallBranch(req, busi.Busi+"/TransOutXa")
assert.Nil(t, err)
busi.BusiConf.Driver = "no-driver"
_, err = xa.CallBranch(req, busi.Busi+"/TransInXa")
assert.Error(t, err)
return nil, err
})
assert.Error(t, err)
waitTransProcessed(gid)
busi.BusiConf.Driver = oldDriver
cronTransOnceForwardNow(t, gid, 500) // rollback succeeded here
assert.Equal(t, StatusFailed, getTransStatus(gid))
assert.Equal(t, []string{StatusSucceed, StatusPrepared}, getBranchesStatus(gid))
}
func TestXaCoverDTMError(t *testing.T) {
gid := dtmimp.GetFuncName()
err := dtmcli.XaGlobalTransaction("localhost:01", gid, func(xa *dtmcli.Xa) (*resty.Response, error) {
return nil, nil
})
assert.Error(t, err)
}
func TestXaCoverGidError(t *testing.T) {
if dtmimp.GetCurrentDBType() != dtmimp.DBTypeMysql {
return
}
gid := dtmimp.GetFuncName() + "-' '"
err := dtmcli.XaGlobalTransaction(DtmServer, gid, func(xa *dtmcli.Xa) (*resty.Response, error) {
req := busi.GenReqHTTP(30, false, false)
_, err := xa.CallBranch(req, busi.Busi+"/TransOutXa")
assert.Error(t, err)
return nil, err
})
assert.Error(t, err)
waitTransProcessed(gid)
}