tests move to a dir
This commit is contained in:
parent
4218256c19
commit
14b7269b22
@ -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
|
||||
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")
|
||||
}
|
||||
}
|
||||
|
||||
var gNode *snowflake.Node = nil
|
||||
|
||||
21
dtmsvr/utils_test.go
Normal file
21
dtmsvr/utils_test.go
Normal file
@ -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()
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
package dtmsvr
|
||||
package test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
@ -1,4 +1,4 @@
|
||||
package dtmsvr
|
||||
package test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@ -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)
|
||||
@ -1,4 +1,4 @@
|
||||
package dtmsvr
|
||||
package test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
@ -1,4 +1,4 @@
|
||||
package dtmsvr
|
||||
package test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@ -1,4 +1,4 @@
|
||||
package dtmsvr
|
||||
package test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
@ -1,4 +1,4 @@
|
||||
package dtmsvr
|
||||
package test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
@ -1,4 +1,4 @@
|
||||
package dtmsvr
|
||||
package test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@ -1,4 +1,4 @@
|
||||
package dtmsvr
|
||||
package test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
@ -1,4 +1,4 @@
|
||||
package dtmsvr
|
||||
package test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
@ -1,4 +1,4 @@
|
||||
package dtmsvr
|
||||
package test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
@ -1,4 +1,4 @@
|
||||
package dtmsvr
|
||||
package test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
29
test/types.go
Normal file
29
test/types.go
Normal file
@ -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
|
||||
@ -1,4 +1,4 @@
|
||||
package dtmsvr
|
||||
package test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
Loading…
x
Reference in New Issue
Block a user