diff --git a/common/types_test.go b/common/types_test.go index bc4f390..fda05db 100644 --- a/common/types_test.go +++ b/common/types_test.go @@ -28,6 +28,8 @@ func TestDb(t *testing.T) { return nil }() assert.NotEqual(t, nil, err) + sdb := db.ToSQLDB() + db = SQLDB2DB(sdb) } func TestDbAlone(t *testing.T) { diff --git a/common/utils_test.go b/common/utils_test.go index 664f543..ecebe8e 100644 --- a/common/utils_test.go +++ b/common/utils_test.go @@ -79,11 +79,16 @@ func TestGin(t *testing.T) { assert.Equal(t, "{\"code\":500,\"message\":\"err1\"}", getResultString("/api/error", strings.NewReader("{}"))) } -// func TestResty(t *testing.T) { -// resp, err := RestyClient.R().Get("http://taobao.com") -// assert.Equal(t, nil, err) -// err2 := CatchP(func() { -// CheckRestySuccess(resp, err) -// }) -// assert.NotEqual(t, nil, err2) -// } +func TestSome(t *testing.T) { + n := MustAtoi("123") + assert.Equal(t, 123, n) + + wd := MustGetwd() + assert.NotEqual(t, "", wd) + + dir1 := GetCurrentCodeDir() + assert.Equal(t, true, strings.HasSuffix(dir1, "common")) + + func1 := GetFuncName() + assert.Equal(t, true, strings.HasSuffix(func1, "TestSome")) +} diff --git a/dtmsvr/cron.go b/dtmsvr/cron.go index ca6c828..69913d7 100644 --- a/dtmsvr/cron.go +++ b/dtmsvr/cron.go @@ -9,16 +9,6 @@ import ( "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 func CronTransOnce(expireIn time.Duration, status string) bool { defer handlePanic() @@ -31,10 +21,10 @@ func CronTransOnce(expireIn time.Duration, status string) bool { return true } -// CronSubmitted cron expired submitted trans forever -func CronSubmitted() { - for { - notEmpty := CronTransOnce(time.Duration(0), "submitted") +// CronExpiredTrans cron expired trans, num == -1 indicate for ever +func CronExpiredTrans(status string, num int) { + for i := 0; i < num || num == -1; i++ { + notEmpty := CronTransOnce(time.Duration(0), status) if !notEmpty { sleepCronTime() } diff --git a/dtmsvr/dtmsvr_test.go b/dtmsvr/dtmsvr_test.go index 2d136ae..28debeb 100644 --- a/dtmsvr/dtmsvr_test.go +++ b/dtmsvr/dtmsvr_test.go @@ -16,13 +16,12 @@ import ( var DtmServer = examples.DtmServer var Busi = examples.Busi -var myinit int = func() int { +func init() { common.InitApp(common.GetProjectDir(), &config) config.Mysql["database"] = dbName PopulateMysql() examples.PopulateMysql() - return 0 -}() +} func TestDtmSvr(t *testing.T) { TransProcessedTestChan = make(chan string, 1) @@ -72,6 +71,8 @@ func TestCover(t *testing.T) { CronTransOnce(0, "submitted") defer handlePanic() checkAffected(db.DB) + + go CronExpiredTrans("submitted", 1) } func getTransStatus(gid string) string { diff --git a/dtmsvr/main.go b/dtmsvr/main.go index 0af5c74..1083eb3 100644 --- a/dtmsvr/main.go +++ b/dtmsvr/main.go @@ -14,8 +14,8 @@ var dtmsvrPort = 8080 // MainStart main func MainStart() { StartSvr() - go CronSubmitted() - go CronPrepared() + go CronExpiredTrans("submitted", -1) + go CronExpiredTrans("prepared", -1) } // StartSvr StartSvr