diff --git a/dtmsvr/cron.go b/dtmsvr/cron.go index 671df25..4f7179e 100644 --- a/dtmsvr/cron.go +++ b/dtmsvr/cron.go @@ -53,11 +53,11 @@ func CronExpiredTrans(num int) { func CronUpdateTopicsMap() { for { time.Sleep(time.Duration(conf.ConfigUpdateInterval) * time.Second) - cronUpdateTopicsMapOnce() + CronUpdateTopicsMapOnce() } } -func cronUpdateTopicsMapOnce() { +func CronUpdateTopicsMapOnce() { defer handlePanic(nil) updateTopicsMap() } diff --git a/dtmsvr/storage/boltdb/boltdb.go b/dtmsvr/storage/boltdb/boltdb.go index 631d73d..eea3a5d 100644 --- a/dtmsvr/storage/boltdb/boltdb.go +++ b/dtmsvr/storage/boltdb/boltdb.go @@ -68,7 +68,8 @@ func initializeBuckets(db *bolt.DB) error { } // cleanupExpiredData will clean the expired data in boltdb, the -// expired time is configurable. +// +// expired time is configurable. func cleanupExpiredData(expire time.Duration, db *bolt.DB) error { if expire <= 0 { return nil @@ -482,7 +483,6 @@ func (s *Store) ResetCronTime(after time.Duration, limit int64) (succeedCount in return } -// ResetTransGlobalCronTime reset nextCronTime of one global trans. func (s *Store) ResetTransGlobalCronTime(g *storage.TransGlobalStore) error { old := g.UpdateTime err := s.boltDb.Update(func(t *bolt.Tx) error { diff --git a/dtmsvr/storage/redis/redis.go b/dtmsvr/storage/redis/redis.go index 090ab59..7a91682 100644 --- a/dtmsvr/storage/redis/redis.go +++ b/dtmsvr/storage/redis/redis.go @@ -330,7 +330,6 @@ return tostring(i) return } -// ResetTransGlobalCronTime reset nextCronTime of one global trans. func (s *Store) ResetTransGlobalCronTime(global *storage.TransGlobalStore) error { now := dtmutil.GetNextTime(0) global.NextCronTime = now diff --git a/dtmsvr/storage/sql/sql.go b/dtmsvr/storage/sql/sql.go index 28f9c9c..98a4501 100644 --- a/dtmsvr/storage/sql/sql.go +++ b/dtmsvr/storage/sql/sql.go @@ -204,7 +204,7 @@ func (s *Store) ResetCronTime(after time.Duration, limit int64) (succeedCount in return affected, affected == limit, err } -// ResetTransGlobalCronTime reset nextCronTime of one global trans. +// reset nextCronTime of one global trans. func (s *Store) ResetTransGlobalCronTime(global *storage.TransGlobalStore) error { now := getTimeStr(0) where := map[string]string{ diff --git a/test/common_test.go b/test/common_test.go index 2fe2724..4974268 100644 --- a/test/common_test.go +++ b/test/common_test.go @@ -1,6 +1,7 @@ package test import ( + "os" "testing" "github.com/dtm-labs/dtm/client/dtmcli" @@ -46,3 +47,9 @@ func TestMustGenGid(t *testing.T) { dtmgrpc.MustGenGid(dtmutil.DefaultGrpcServer) dtmcli.MustGenGid(dtmutil.DefaultHTTPServer) } + +func MaySkipMongo(t *testing.T) { + if os.Getenv("SKIP_MONGO") != "" { + t.Skip("skipping test with mongo") + } +} diff --git a/test/main_test.go b/test/main_test.go index 665eed5..b91e9dd 100644 --- a/test/main_test.go +++ b/test/main_test.go @@ -37,6 +37,7 @@ func TestMain(m *testing.M) { dtmdriver.Middlewares.Grpc = append(dtmdriver.Middlewares.Grpc, busi.SetGrpcHeaderForHeadersYes) tenv := dtmimp.OrString(os.Getenv("TEST_STORE"), config.Redis) + conf.ConfigUpdateInterval = 1 conf.Store.Host = "localhost" conf.Store.Driver = tenv if tenv == "boltdb" { @@ -74,7 +75,8 @@ func TestMain(m *testing.M) { subscribeTopic() subscribeGrpcTopic() - + dtmsvr.CronUpdateTopicsMapOnce() + logger.Debugf("unit main test inited") r := m.Run() if r != 0 { os.Exit(r) diff --git a/test/msg_barrier_mongo_test.go b/test/msg_barrier_mongo_test.go index 32bb0f0..50e60e8 100644 --- a/test/msg_barrier_mongo_test.go +++ b/test/msg_barrier_mongo_test.go @@ -12,6 +12,7 @@ import ( ) func TestMsgMongoDoSucceed(t *testing.T) { + MaySkipMongo(t) before := getBeforeBalances("mongo") gid := dtmimp.GetFuncName() req := busi.GenReqHTTP(30, false, false) @@ -30,6 +31,7 @@ func TestMsgMongoDoSucceed(t *testing.T) { } func TestMsgMongoDoBusiFailed(t *testing.T) { + MaySkipMongo(t) before := getBeforeBalances("mongo") gid := dtmimp.GetFuncName() req := busi.GenReqHTTP(30, false, false) @@ -43,6 +45,7 @@ func TestMsgMongoDoBusiFailed(t *testing.T) { } func TestMsgMongoDoBusiLater(t *testing.T) { + MaySkipMongo(t) before := getBeforeBalances("mongo") gid := dtmimp.GetFuncName() req := busi.GenReqHTTP(30, false, false) @@ -68,6 +71,7 @@ func TestMsgMongoDoBusiLater(t *testing.T) { } func TestMsgMongoDoCommitFailed(t *testing.T) { + MaySkipMongo(t) before := getBeforeBalances("mongo") gid := dtmimp.GetFuncName() req := busi.GenReqHTTP(30, false, false) @@ -85,6 +89,7 @@ func TestMsgMongoDoCommitFailed(t *testing.T) { } func TestMsgMongoDoCommitAfterFailed(t *testing.T) { + MaySkipMongo(t) before := getBeforeBalances("mongo") gid := dtmimp.GetFuncName() req := busi.GenReqHTTP(30, false, false) diff --git a/test/msg_grpc_test.go b/test/msg_grpc_test.go index a65a88a..3c2fd1f 100644 --- a/test/msg_grpc_test.go +++ b/test/msg_grpc_test.go @@ -9,7 +9,6 @@ package test import ( "fmt" "testing" - "time" "github.com/dtm-labs/dtm/client/dtmcli" "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" @@ -70,7 +69,4 @@ func genGrpcMsg(gid string) *dtmgrpc.MsgGrpc { func subscribeGrpcTopic() { e2p(grpcSubscribe("grpc_trans", busi.BusiGrpc+"/busi.Busi/TransOut")) e2p(grpcSubscribe("grpc_trans", busi.BusiGrpc+"/busi.Busi/TransIn")) - - // wait for the topic configuration to take effect - time.Sleep(time.Second * time.Duration(conf.ConfigUpdateInterval+1)) } diff --git a/test/msg_test.go b/test/msg_test.go index e07ae13..7f86808 100644 --- a/test/msg_test.go +++ b/test/msg_test.go @@ -9,7 +9,6 @@ package test import ( "strings" "testing" - "time" "github.com/dtm-labs/dtm/client/dtmcli" "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" @@ -89,7 +88,4 @@ func genMsg(gid string) *dtmcli.Msg { func subscribeTopic() { e2p(httpSubscribe("http_trans", busi.Busi+"/TransOut")) e2p(httpSubscribe("http_trans", busi.Busi+"/TransIn")) - - // wait for the topic configuration to take effect - time.Sleep(time.Second * time.Duration(conf.ConfigUpdateInterval+1)) } diff --git a/test/saga_barrier_mongo_test.go b/test/saga_barrier_mongo_test.go index 0cf2b61..789dc35 100644 --- a/test/saga_barrier_mongo_test.go +++ b/test/saga_barrier_mongo_test.go @@ -16,6 +16,7 @@ import ( ) func TestSagaBarrierMongoNormal(t *testing.T) { + MaySkipMongo(t) before := getBeforeBalances("mongo") saga := genSagaBarrierMongo(dtmimp.GetFuncName(), false) err := saga.Submit() @@ -27,6 +28,7 @@ func TestSagaBarrierMongoNormal(t *testing.T) { } func TestSagaBarrierMongoRollback(t *testing.T) { + MaySkipMongo(t) before := getBeforeBalances("mongo") saga := genSagaBarrierMongo(dtmimp.GetFuncName(), true) err := saga.Submit()