Browse Source

golang ci lint

pull/227/head
xyctruth 4 years ago
parent
commit
2c7e53cfe7
  1. 2
      dtmsvr/api_http.go
  2. 5
      dtmsvr/storage/boltdb/boltdb.go
  3. 1
      dtmsvr/storage/redis/redis.go
  4. 2
      dtmsvr/storage/sql/sql.go
  5. 9
      test/store_test.go

2
dtmsvr/api_http.go

@ -83,6 +83,8 @@ func all(c *gin.Context) interface{} {
return map[string]interface{}{"transactions": globals, "next_position": position}
}
// resetCronTime rest nextCronTime
// Prevent multiple backoff from causing NextCronTime to be too long
func resetCronTime(c *gin.Context) interface{} {
sTimeoutSecond := dtmimp.OrString(c.Query("timeout"), strconv.FormatInt(3*conf.TimeoutToFail, 10))
sLimit := dtmimp.OrString(c.Query("limit"), "100")

5
dtmsvr/storage/boltdb/boltdb.go

@ -14,14 +14,11 @@ import (
"github.com/dtm-labs/dtm/dtmcli"
"github.com/dtm-labs/dtm/dtmcli/dtmimp"
"github.com/dtm-labs/dtm/dtmcli/logger"
"github.com/dtm-labs/dtm/dtmsvr/config"
"github.com/dtm-labs/dtm/dtmsvr/storage"
"github.com/dtm-labs/dtm/dtmutil"
bolt "go.etcd.io/bbolt"
)
var conf = &config.Config
// Store implements storage.Store, and storage with boltdb
type Store struct {
boltDb *bolt.DB
@ -412,6 +409,8 @@ func (s *Store) LockOneGlobalTrans(expireIn time.Duration) *storage.TransGlobalS
return trans
}
// ResetCronTime rest nextCronTime
// Prevent multiple backoff from causing NextCronTime to be too long
func (s *Store) ResetCronTime(timeout time.Duration, limit int64) error {
next := time.Now()
var trans *storage.TransGlobalStore

1
dtmsvr/storage/redis/redis.go

@ -261,6 +261,7 @@ return gid
}
// ResetCronTime rest nextCronTime
// Prevent multiple backoff from causing NextCronTime to be too long
func (s *Store) ResetCronTime(timeout time.Duration, limit int64) error {
next := time.Now().Unix()
timeoutTimestamp := time.Now().Add(timeout).Unix()

2
dtmsvr/storage/sql/sql.go

@ -156,6 +156,8 @@ func (s *Store) LockOneGlobalTrans(expireIn time.Duration) *storage.TransGlobalS
return global
}
// ResetCronTime rest nextCronTime
// Prevent multiple backoff from causing NextCronTime to be too long
func (s *Store) ResetCronTime(timeout time.Duration, limit int64) error {
db := dbGet()
getTime := func(second int) string {

9
test/store_test.go

@ -136,7 +136,8 @@ func testStoreResetCronTime(t *testing.T, funcName string, restCronHandler func(
assert.Nil(t, g)
// Rest 1 count
err = restCronHandler(restTimeTimeout, limit)
err1 := restCronHandler(restTimeTimeout, limit)
assert.Nil(t, err1)
// Fount 1 count
g = s.LockOneGlobalTrans(time.Duration(lockExpireIn) * time.Second)
assert.NotNil(t, g)
@ -146,9 +147,9 @@ func testStoreResetCronTime(t *testing.T, funcName string, restCronHandler func(
g = s.LockOneGlobalTrans(time.Duration(lockExpireIn) * time.Second)
assert.Nil(t, g)
// Increase the restTimeTimeout, Rest 1 count
err = restCronHandler(restTimeTimeout-12, limit)
assert.Nil(t, err)
// reduce the restTimeTimeout, Rest 1 count
err2 := restCronHandler(restTimeTimeout-12, limit)
assert.Nil(t, err2)
// Fount 1 count
g = s.LockOneGlobalTrans(time.Duration(lockExpireIn) * time.Second)
assert.NotNil(t, g)

Loading…
Cancel
Save