Browse Source

tests move to a dir

pull/25/head
yedf2 5 years ago
parent
commit
14b7269b22
  1. 15
      dtmsvr/utils.go
  2. 21
      dtmsvr/utils_test.go
  3. 2
      test/barrier_saga_test.go
  4. 2
      test/barrier_tcc_test.go
  5. 22
      test/dtmsvr_test.go
  6. 2
      test/examples_test.go
  7. 2
      test/grpc_msg_test.go
  8. 2
      test/grpc_saga_test.go
  9. 2
      test/grpc_tcc_test.go
  10. 2
      test/grpc_xa_test.go
  11. 2
      test/msg_test.go
  12. 2
      test/saga_test.go
  13. 2
      test/tcc_test.go
  14. 2
      test/trans_xa_test.go
  15. 29
      test/types.go
  16. 2
      test/wait_saga_test.go

15
dtmsvr/utils.go

@ -5,6 +5,7 @@ import (
"fmt"
"net"
"strings"
"time"
"github.com/bwmarrin/snowflake"
"github.com/yedf/dtm/common"
@ -41,12 +42,16 @@ var TransProcessedTestChan chan string = nil
// WaitTransProcessed only for test usage. wait for transaction processed once
func WaitTransProcessed(gid string) {
dtmcli.Logf("waiting for gid %s", gid)
id := <-TransProcessedTestChan
for id != gid {
dtmcli.LogRedf("-------id %s not match gid %s", id, gid)
id = <-TransProcessedTestChan
select {
case id := <-TransProcessedTestChan:
for id != gid {
dtmcli.LogRedf("-------id %s not match gid %s", id, gid)
id = <-TransProcessedTestChan
}
dtmcli.Logf("finish for gid %s", gid)
case <-time.After(time.Duration(time.Second * 3)):
dtmcli.LogFatalf("Wait Trans timeout")
}
dtmcli.Logf("finish for gid %s", gid)
}
var gNode *snowflake.Node = nil

21
dtmsvr/utils_test.go

@ -0,0 +1,21 @@
package dtmsvr
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/yedf/dtm/dtmcli"
)
func TestUtils(t *testing.T) {
db := dbGet()
db.NoMust()
CronTransOnce(0)
err := dtmcli.CatchP(func() {
checkAffected(db.DB)
})
assert.Error(t, err)
CronExpiredTrans(1)
go sleepCronTime()
}

2
dtmsvr/trans_barrier_saga_test.go → test/barrier_saga_test.go

@ -1,4 +1,4 @@
package dtmsvr
package test
import (
"testing"

2
dtmsvr/trans_barrier_tcc_test.go → test/barrier_tcc_test.go

@ -1,4 +1,4 @@
package dtmsvr
package test
import (
"fmt"

22
dtmsvr/dtmsvr_test.go → test/dtmsvr_test.go

@ -1,4 +1,4 @@
package dtmsvr
package test
import (
"database/sql"
@ -9,6 +9,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/yedf/dtm/common"
"github.com/yedf/dtm/dtmcli"
"github.com/yedf/dtm/dtmsvr"
"github.com/yedf/dtm/examples"
)
@ -41,11 +42,11 @@ func resetXaData() {
}
func TestMain(m *testing.M) {
TransProcessedTestChan = make(chan string, 1)
PopulateDB(false)
dtmsvr.TransProcessedTestChan = make(chan string, 1)
dtmsvr.PopulateDB(false)
examples.PopulateDB(false)
// 启动组件
go StartSvr()
go dtmsvr.StartSvr()
examples.GrpcStartup()
app = examples.BaseAppStartup()
@ -53,19 +54,6 @@ func TestMain(m *testing.M) {
m.Run()
}
func TestCover(t *testing.T) {
db := dbGet()
db.NoMust()
CronTransOnce(0)
err := dtmcli.CatchP(func() {
checkAffected(db.DB)
})
assert.Error(t, err)
CronExpiredTrans(1)
go sleepCronTime()
}
func getTransStatus(gid string) string {
sm := TransGlobal{}
dbr := dbGet().Model(&sm).Where("gid=?", gid).First(&sm)

2
dtmsvr/examples_test.go → test/examples_test.go

@ -1,4 +1,4 @@
package dtmsvr
package test
import (
"testing"

2
dtmsvr/trans_grpc_msg_test.go → test/grpc_msg_test.go

@ -1,4 +1,4 @@
package dtmsvr
package test
import (
"fmt"

2
dtmsvr/trans_grpc_saga_test.go → test/grpc_saga_test.go

@ -1,4 +1,4 @@
package dtmsvr
package test
import (
"testing"

2
dtmsvr/trans_grpc_tcc_test.go → test/grpc_tcc_test.go

@ -1,4 +1,4 @@
package dtmsvr
package test
import (
"testing"

2
dtmsvr/trans_grpc_xa_test.go → test/grpc_xa_test.go

@ -1,4 +1,4 @@
package dtmsvr
package test
import (
"fmt"

2
dtmsvr/trans_msg_test.go → test/msg_test.go

@ -1,4 +1,4 @@
package dtmsvr
package test
import (
"testing"

2
dtmsvr/trans_saga_test.go → test/saga_test.go

@ -1,4 +1,4 @@
package dtmsvr
package test
import (
"testing"

2
dtmsvr/trans_tcc_test.go → test/tcc_test.go

@ -1,4 +1,4 @@
package dtmsvr
package test
import (
"testing"

2
dtmsvr/trans_xa_test.go → test/trans_xa_test.go

@ -1,4 +1,4 @@
package dtmsvr
package test
import (
"fmt"

29
test/types.go

@ -0,0 +1,29 @@
package test
import (
"github.com/yedf/dtm/common"
"github.com/yedf/dtm/dtmcli"
"github.com/yedf/dtm/dtmsvr"
)
var config = common.DtmConfig
func dbGet() *common.DB {
return common.DbGet(config.DB)
}
// WaitTransProcessed alias
var WaitTransProcessed = dtmsvr.WaitTransProcessed
// CronTransOnce alias
var CronTransOnce = dtmsvr.CronTransOnce
var e2p = dtmcli.E2P
// TransGlobal alias
type TransGlobal = dtmsvr.TransGlobal
// TransBranch alias
type TransBranch = dtmsvr.TransBranch
// M alias
type M = dtmcli.M

2
dtmsvr/trans_wait_saga_test.go → test/wait_saga_test.go

@ -1,4 +1,4 @@
package dtmsvr
package test
import (
"testing"
Loading…
Cancel
Save