tests move to a dir
This commit is contained in:
parent
4218256c19
commit
14b7269b22
@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/bwmarrin/snowflake"
|
"github.com/bwmarrin/snowflake"
|
||||||
"github.com/yedf/dtm/common"
|
"github.com/yedf/dtm/common"
|
||||||
@ -41,12 +42,16 @@ var TransProcessedTestChan chan string = nil
|
|||||||
// WaitTransProcessed only for test usage. wait for transaction processed once
|
// WaitTransProcessed only for test usage. wait for transaction processed once
|
||||||
func WaitTransProcessed(gid string) {
|
func WaitTransProcessed(gid string) {
|
||||||
dtmcli.Logf("waiting for gid %s", gid)
|
dtmcli.Logf("waiting for gid %s", gid)
|
||||||
id := <-TransProcessedTestChan
|
select {
|
||||||
for id != gid {
|
case id := <-TransProcessedTestChan:
|
||||||
dtmcli.LogRedf("-------id %s not match gid %s", id, gid)
|
for id != gid {
|
||||||
id = <-TransProcessedTestChan
|
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
|
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 (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package dtmsvr
|
package test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package dtmsvr
|
package test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
@ -9,6 +9,7 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/yedf/dtm/common"
|
"github.com/yedf/dtm/common"
|
||||||
"github.com/yedf/dtm/dtmcli"
|
"github.com/yedf/dtm/dtmcli"
|
||||||
|
"github.com/yedf/dtm/dtmsvr"
|
||||||
"github.com/yedf/dtm/examples"
|
"github.com/yedf/dtm/examples"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -41,11 +42,11 @@ func resetXaData() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
TransProcessedTestChan = make(chan string, 1)
|
dtmsvr.TransProcessedTestChan = make(chan string, 1)
|
||||||
PopulateDB(false)
|
dtmsvr.PopulateDB(false)
|
||||||
examples.PopulateDB(false)
|
examples.PopulateDB(false)
|
||||||
// 启动组件
|
// 启动组件
|
||||||
go StartSvr()
|
go dtmsvr.StartSvr()
|
||||||
examples.GrpcStartup()
|
examples.GrpcStartup()
|
||||||
app = examples.BaseAppStartup()
|
app = examples.BaseAppStartup()
|
||||||
|
|
||||||
@ -53,19 +54,6 @@ func TestMain(m *testing.M) {
|
|||||||
m.Run()
|
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 {
|
func getTransStatus(gid string) string {
|
||||||
sm := TransGlobal{}
|
sm := TransGlobal{}
|
||||||
dbr := dbGet().Model(&sm).Where("gid=?", gid).First(&sm)
|
dbr := dbGet().Model(&sm).Where("gid=?", gid).First(&sm)
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package dtmsvr
|
package test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package dtmsvr
|
package test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package dtmsvr
|
package test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package dtmsvr
|
package test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package dtmsvr
|
package test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package dtmsvr
|
package test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package dtmsvr
|
package test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package dtmsvr
|
package test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package dtmsvr
|
package test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"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 (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
Loading…
x
Reference in New Issue
Block a user