update test case

This commit is contained in:
yedongfu 2021-07-16 15:36:07 +08:00
parent 6a4b9d5323
commit 28b8f91969
5 changed files with 25 additions and 27 deletions

View File

@ -28,6 +28,8 @@ func TestDb(t *testing.T) {
return nil return nil
}() }()
assert.NotEqual(t, nil, err) assert.NotEqual(t, nil, err)
sdb := db.ToSQLDB()
db = SQLDB2DB(sdb)
} }
func TestDbAlone(t *testing.T) { func TestDbAlone(t *testing.T) {

View File

@ -79,11 +79,16 @@ func TestGin(t *testing.T) {
assert.Equal(t, "{\"code\":500,\"message\":\"err1\"}", getResultString("/api/error", strings.NewReader("{}"))) assert.Equal(t, "{\"code\":500,\"message\":\"err1\"}", getResultString("/api/error", strings.NewReader("{}")))
} }
// func TestResty(t *testing.T) { func TestSome(t *testing.T) {
// resp, err := RestyClient.R().Get("http://taobao.com") n := MustAtoi("123")
// assert.Equal(t, nil, err) assert.Equal(t, 123, n)
// err2 := CatchP(func() {
// CheckRestySuccess(resp, err) wd := MustGetwd()
// }) assert.NotEqual(t, "", wd)
// assert.NotEqual(t, nil, err2)
// } dir1 := GetCurrentCodeDir()
assert.Equal(t, true, strings.HasSuffix(dir1, "common"))
func1 := GetFuncName()
assert.Equal(t, true, strings.HasSuffix(func1, "TestSome"))
}

View File

@ -9,16 +9,6 @@ import (
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
// CronPrepared cron expired prepared trans forever
func CronPrepared() {
for {
notEmpty := CronTransOnce(time.Duration(0), "prepared")
if !notEmpty {
sleepCronTime()
}
}
}
// CronTransOnce cron expired trans who's status match param status for once. use expireIn as expire time // CronTransOnce cron expired trans who's status match param status for once. use expireIn as expire time
func CronTransOnce(expireIn time.Duration, status string) bool { func CronTransOnce(expireIn time.Duration, status string) bool {
defer handlePanic() defer handlePanic()
@ -31,10 +21,10 @@ func CronTransOnce(expireIn time.Duration, status string) bool {
return true return true
} }
// CronSubmitted cron expired submitted trans forever // CronExpiredTrans cron expired trans, num == -1 indicate for ever
func CronSubmitted() { func CronExpiredTrans(status string, num int) {
for { for i := 0; i < num || num == -1; i++ {
notEmpty := CronTransOnce(time.Duration(0), "submitted") notEmpty := CronTransOnce(time.Duration(0), status)
if !notEmpty { if !notEmpty {
sleepCronTime() sleepCronTime()
} }

View File

@ -16,13 +16,12 @@ import (
var DtmServer = examples.DtmServer var DtmServer = examples.DtmServer
var Busi = examples.Busi var Busi = examples.Busi
var myinit int = func() int { func init() {
common.InitApp(common.GetProjectDir(), &config) common.InitApp(common.GetProjectDir(), &config)
config.Mysql["database"] = dbName config.Mysql["database"] = dbName
PopulateMysql() PopulateMysql()
examples.PopulateMysql() examples.PopulateMysql()
return 0 }
}()
func TestDtmSvr(t *testing.T) { func TestDtmSvr(t *testing.T) {
TransProcessedTestChan = make(chan string, 1) TransProcessedTestChan = make(chan string, 1)
@ -72,6 +71,8 @@ func TestCover(t *testing.T) {
CronTransOnce(0, "submitted") CronTransOnce(0, "submitted")
defer handlePanic() defer handlePanic()
checkAffected(db.DB) checkAffected(db.DB)
go CronExpiredTrans("submitted", 1)
} }
func getTransStatus(gid string) string { func getTransStatus(gid string) string {

View File

@ -14,8 +14,8 @@ var dtmsvrPort = 8080
// MainStart main // MainStart main
func MainStart() { func MainStart() {
StartSvr() StartSvr()
go CronSubmitted() go CronExpiredTrans("submitted", -1)
go CronPrepared() go CronExpiredTrans("prepared", -1)
} }
// StartSvr StartSvr // StartSvr StartSvr