Browse Source

update test

pull/443/head
yedf2 3 years ago
parent
commit
8cac60ead2
  1. 4
      dtmsvr/cron.go
  2. 4
      dtmsvr/storage/boltdb/boltdb.go
  3. 1
      dtmsvr/storage/redis/redis.go
  4. 2
      dtmsvr/storage/sql/sql.go
  5. 7
      test/common_test.go
  6. 4
      test/main_test.go
  7. 5
      test/msg_barrier_mongo_test.go
  8. 4
      test/msg_grpc_test.go
  9. 4
      test/msg_test.go
  10. 2
      test/saga_barrier_mongo_test.go

4
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()
}

4
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 {

1
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

2
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{

7
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")
}
}

4
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)

5
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)

4
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))
}

4
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))
}

2
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()

Loading…
Cancel
Save