test(clustermgr): shorten duration of clustermgr testing

1. start raft in millisecond.
 2. close service in background.

Signed-off-by: slasher <mcq.sejust@gmail.com>
This commit is contained in:
slasher 2022-08-24 11:15:03 +08:00 committed by leonrayang
parent c3509104d8
commit b7d648c52e
11 changed files with 185 additions and 195 deletions

View File

@ -15,24 +15,20 @@
package clustermgr
import (
"context"
"encoding/json"
"testing"
"github.com/cubefs/cubefs/blobstore/api/clustermgr"
"github.com/cubefs/cubefs/blobstore/common/proto"
"github.com/cubefs/cubefs/blobstore/common/trace"
"github.com/stretchr/testify/require"
)
func TestConfig(t *testing.T) {
testService := initTestService(t)
defer clear(testService)
defer testService.Close()
testService, clean := initTestService(t)
defer clean()
testClusterClient := initTestClusterClient(testService)
_, ctx := trace.StartSpanFromContext(context.Background(), "")
ctx := newCtx()
// test set config
{

View File

@ -15,14 +15,12 @@
package clustermgr
import (
"context"
"strconv"
"testing"
"github.com/cubefs/cubefs/blobstore/api/blobnode"
"github.com/cubefs/cubefs/blobstore/api/clustermgr"
"github.com/cubefs/cubefs/blobstore/common/proto"
"github.com/cubefs/cubefs/blobstore/common/trace"
"github.com/stretchr/testify/require"
)
@ -42,8 +40,7 @@ var testDiskInfo = blobnode.DiskInfo{
}
func insertDiskInfos(t *testing.T, client *clustermgr.Client, start, end int, idcs ...string) {
_, ctx := trace.StartSpanFromContext(context.Background(), "")
ctx := newCtx()
for idx, idc := range idcs {
for i := start; i <= end; i++ {
_, err := client.AllocDiskID(ctx)
@ -61,12 +58,10 @@ func insertDiskInfos(t *testing.T, client *clustermgr.Client, start, end int, id
}
func TestDisk(t *testing.T) {
testService := initTestService(t)
defer clear(testService)
defer testService.Close()
testService, clean := initTestService(t)
defer clean()
testClusterClient := initTestClusterClient(testService)
_, ctx := trace.StartSpanFromContext(context.Background(), "")
ctx := newCtx()
// test disk id alloc
{

View File

@ -15,22 +15,17 @@
package clustermgr
import (
"context"
"fmt"
"testing"
"github.com/stretchr/testify/require"
"github.com/cubefs/cubefs/blobstore/common/trace"
)
func TestKV(t *testing.T) {
testService := initTestService(t)
defer clear(testService)
defer testService.Close()
testService, clean := initTestService(t)
defer clean()
testClusterClient := initTestClusterClient(testService)
_, ctx := trace.StartSpanFromContext(context.Background(), "")
ctx := newCtx()
err := testClusterClient.SetKV(ctx, "test1", []byte("value"))
require.NoError(t, err)
@ -54,13 +49,10 @@ func TestKV(t *testing.T) {
}
func BenchmarkService_KvSet(b *testing.B) {
testService := initTestService(&testing.T{})
defer clear(testService)
defer testService.Close()
testService, clean := initTestService(b)
defer clean()
testClusterClient := initTestClusterClient(testService)
_, ctx := trace.StartSpanFromContext(context.Background(), "")
testCases := []struct {
key string
value []byte
@ -71,6 +63,7 @@ func BenchmarkService_KvSet(b *testing.B) {
{key: "test4", value: []byte("test-repair")},
}
ctx := newCtx()
b.ResetTimer()
for i, tCase := range testCases {
b.Run(fmt.Sprintf("case-%d", i), func(b *testing.B) {

View File

@ -1,7 +1,6 @@
package clustermgr
import (
"context"
"encoding/binary"
"io"
"os"
@ -19,16 +18,13 @@ import (
apierrors "github.com/cubefs/cubefs/blobstore/common/errors"
"github.com/cubefs/cubefs/blobstore/common/kvstore"
"github.com/cubefs/cubefs/blobstore/common/rpc"
"github.com/cubefs/cubefs/blobstore/common/trace"
)
func TestManage(t *testing.T) {
testService := initTestService(t)
defer clear(testService)
defer testService.Close()
testService, clean := initTestService(t)
defer clean()
testClusterClient := initTestClusterClient(testService)
_, ctx := trace.StartSpanFromContext(context.Background(), "")
ctx := newCtx()
// test member add or remove
{
@ -49,7 +45,6 @@ func TestManage(t *testing.T) {
err = testClusterClient.AddMember(ctx, &clustermgr.AddMemberArgs{PeerID: 2, Host: "127.0.0.1", NodeHost: "127.0.0.2", MemberType: clustermgr.MemberTypeNormal})
require.Equal(t, apierrors.CodeDuplicatedMemberInfo, err.(rpc.HTTPError).StatusCode())
}
// test stat

View File

@ -15,23 +15,19 @@
package clustermgr
import (
"context"
"strconv"
"testing"
"github.com/stretchr/testify/require"
"github.com/cubefs/cubefs/blobstore/api/clustermgr"
"github.com/cubefs/cubefs/blobstore/common/trace"
)
func TestService(t *testing.T) {
testService := initTestService(t)
defer clear(testService)
defer testService.Close()
testService, clean := initTestService(t)
defer clean()
testClusterClient := initTestClusterClient(testService)
_, ctx := trace.StartSpanFromContext(context.Background(), "")
ctx := newCtx()
testServiceName := "testService"
testHostPrefix := "http://127.0.0."

View File

@ -24,17 +24,17 @@ import (
)
func TestStateMachine(t *testing.T) {
srcService := initTestService(t)
defer clear(srcService)
defer srcService.Close()
srcService, srcClean := initTestService(t)
defer srcClean()
srcClusterClient := initTestClusterClient(srcService)
// change another listen port
oldPort := testServiceCfg.RaftConfig.ServerConfig.ListenPort
oldMembers := testServiceCfg.RaftConfig.ServerConfig.Members
testServiceCfg.RaftConfig.ServerConfig.ListenPort = GetFreePort()
testServiceCfg.RaftConfig.ServerConfig.Members = []raftserver.Member{{NodeID: 1, Host: "127.0.0.1:65342", Learner: false}}
testServiceCfg.RaftConfig.ServerConfig.Members = []raftserver.Member{
{NodeID: 1, Host: "127.0.0.1:65342", Learner: false},
}
testServiceCfg.CodeModePolicies = []codemode.Policy{
{
ModeName: codemode.EC15P12.Name(),
@ -51,11 +51,11 @@ func TestStateMachine(t *testing.T) {
Enable: false,
},
}
destService := initTestService(t)
destService, destClean := initTestService(t)
defer destClean()
testServiceCfg.RaftConfig.ServerConfig.ListenPort = oldPort
testServiceCfg.RaftConfig.ServerConfig.Members = oldMembers
defer clear(destService)
defer destService.Close()
insertDiskInfos(t, srcClusterClient, 1, 10, "z0")

View File

@ -16,12 +16,13 @@ package clustermgr
import (
"context"
"fmt"
"math/rand"
"net"
"net/http"
"net/http/httptest"
"os"
"strconv"
"sync"
"testing"
"github.com/stretchr/testify/require"
@ -41,7 +42,7 @@ var testServiceCfg = &Config{
IDC: []string{"z0", "z1", "z2"},
ClusterID: 1,
Readonly: false,
DBPath: "/tmp/tmpsvrdb-" + strconv.Itoa(rand.Intn(100000000)),
DBPath: "/tmp/tmpsvrdb-" + randID(),
CodeModePolicies: []codemode.Policy{
{
ModeName: codemode.EC15P12.Name(),
@ -69,8 +70,10 @@ var testServiceCfg = &Config{
ListenPort: GetFreePort(),
TickInterval: 1,
ElectionTick: 2,
WalDir: "/tmp/tmpsvrraftwal-" + strconv.Itoa(rand.Intn(10000000)),
WalDir: "/tmp/tmpsvrraftwal-" + randID(),
Members: []raftserver.Member{{NodeID: 1, Host: "127.0.0.1:60110", Learner: false}},
TickIntervalMs: 20,
},
},
DiskMgrConfig: diskmgr.DiskMgrConfig{
@ -80,28 +83,57 @@ var testServiceCfg = &Config{
},
}
func clear(testService *Service) {
var (
cleanWG sync.WaitGroup
newCtx = func() context.Context {
_, ctx := trace.StartSpanFromContext(context.Background(), "")
return ctx
}
)
func TestMain(m *testing.M) {
exitCode := m.Run()
cleanWG.Wait()
os.Exit(exitCode)
}
func randID() string {
return fmt.Sprintf("%010d", rand.Intn(100000000))
}
func cleanTestService(testService *Service) {
testService.Close()
os.RemoveAll(testService.DBPath)
os.RemoveAll(testService.RaftConfig.ServerConfig.WalDir)
}
func initTestService(t *testing.T) *Service {
func initTestService(t testing.TB) (*Service, func()) {
cfg := *testServiceCfg
cfg.NormalDBPath = cfg.DBPath + "/normaldb" + strconv.Itoa(rand.Intn(100000000))
cfg.KvDBPath = cfg.DBPath + "/kvdb" + strconv.Itoa(rand.Intn(100000000))
cfg.VolumeMgrConfig.VolumeDBPath = cfg.DBPath + "/volumedb" + strconv.Itoa(rand.Intn(10000000))
cfg.RaftConfig.RaftDBPath = cfg.DBPath + "/raftdb" + strconv.Itoa(rand.Intn(10000000))
cfg.RaftConfig.ServerConfig.WalDir = "/tmp/tmpsvrraftwal-" + strconv.Itoa(rand.Intn(10000000))
cfg.DBPath = "/tmp/tmpsvrdb-" + randID()
cfg.NormalDBPath = cfg.DBPath + "/normaldb-" + randID()
cfg.KvDBPath = cfg.DBPath + "/kvdb-" + randID()
cfg.VolumeMgrConfig.VolumeDBPath = cfg.DBPath + "/volumedb-" + randID()
cfg.RaftConfig.RaftDBPath = cfg.DBPath + "/raftdb-" + randID()
cfg.RaftConfig.ServerConfig.WalDir = "/tmp/tmpsvrraftwal-" + randID()
cfg.RaftConfig.ServerConfig.ListenPort = GetFreePort()
cfg.RaftConfig.ServerConfig.Members = []raftserver.Member{
{NodeID: 1, Host: fmt.Sprintf("127.0.0.1:%d", GetFreePort()), Learner: false},
}
cfg.ClusterCfg[proto.VolumeReserveSizeKey] = "20000000"
os.Mkdir(cfg.DBPath, 0o755)
testService, err := New(&cfg)
require.NoError(t, err)
return testService
cleanWG.Add(1)
return testService, func() {
go func() {
cleanTestService(testService)
cleanWG.Done()
}()
}
}
func initTestClusterClient(testService *Service) *clustermgr.Client {
// mux := server.MockRegist(testService, http.NewServeMux())
ph := rpc.DefaultRouter.Router.PanicHandler
rpc.DefaultRouter = rpc.New()
rpc.DefaultRouter.Router.PanicHandler = ph
@ -115,12 +147,11 @@ func initTestClusterClient(testService *Service) *clustermgr.Client {
}
func TestBidAlloc(t *testing.T) {
testService := initTestService(t)
defer clear(testService)
defer testService.Close()
testService, clean := initTestService(t)
defer clean()
testClusterClient := initTestClusterClient(testService)
ctx := newCtx()
_, ctx := trace.StartSpanFromContext(context.Background(), "")
// test bid alloc
{
ret, err := testClusterClient.AllocBid(ctx, &clustermgr.BidScopeArgs{Count: 10})
@ -135,16 +166,9 @@ func TestBidAlloc(t *testing.T) {
type mockWriter struct{}
func (m *mockWriter) Write(data []byte) (int, error) {
return len(data), nil
}
func (m *mockWriter) Header() http.Header {
return http.Header{}
}
func (m *mockWriter) WriteHeader(statusCode int) {
}
func (mockWriter) Write(data []byte) (int, error) { return len(data), nil }
func (mockWriter) Header() http.Header { return http.Header{} }
func (mockWriter) WriteHeader(statusCode int) {}
func TestNewService(t *testing.T) {
cfg := *testServiceCfg
@ -153,7 +177,7 @@ func TestNewService(t *testing.T) {
cfg.MetricReportIntervalM = 0
cfg.HeartbeatNotifyIntervalS = 0
cfg.RaftConfig.ServerConfig.WalDir = "/tmp/tmpsvrraftwal-" + strconv.Itoa(rand.Intn(10000000))
cfg.RaftConfig.ServerConfig.WalDir = "/tmp/tmpsvrraftwal-" + randID()
cfg.ClusterCfg[proto.VolumeReserveSizeKey] = "20000000"
os.Mkdir(cfg.DBPath, 0o755)
@ -167,10 +191,9 @@ func TestNewService(t *testing.T) {
req, err := http.NewRequest(http.MethodPost, "/", nil)
require.NoError(t, err)
testService.forwardToLeader(&mockWriter{}, req)
testService.forwardToLeader(mockWriter{}, req)
defer clear(testService)
defer testService.Close()
cleanTestService(testService)
}
func GetFreePort() int {

View File

@ -30,25 +30,38 @@ import (
"github.com/cubefs/cubefs/blobstore/clustermgr/persistence/volumedb"
"github.com/cubefs/cubefs/blobstore/common/codemode"
"github.com/cubefs/cubefs/blobstore/common/proto"
"github.com/cubefs/cubefs/blobstore/common/trace"
"github.com/cubefs/cubefs/blobstore/util/log"
"github.com/cubefs/cubefs/blobstore/common/raftserver"
)
// generate 10 volume in db
func initServiceWithData() *Service {
func initServiceWithData() (*Service, func()) {
cfg := *testServiceCfg
cfg.DBPath = "/tmp/tmpsvrdb-" + randID()
cfg.VolumeMgrConfig.FlushIntervalS = 600
cfg.VolumeMgrConfig.MinAllocableVolumeCount = 0
cfg.DiskMgrConfig.HeartbeatExpireIntervalS = 600
cfg.ClusterReportIntervalS = 3
cfg.ClusterCfg[proto.VolumeReserveSizeKey] = "20000000"
cfg.RaftConfig.ServerConfig.ListenPort = GetFreePort()
cfg.RaftConfig.ServerConfig.Members = []raftserver.Member{
{NodeID: 1, Host: fmt.Sprintf("127.0.0.1:%d", GetFreePort()), Learner: false},
}
os.Mkdir(cfg.DBPath, 0o755)
generateVolume(cfg.DBPath+"/volumedb", cfg.DBPath+"/normaldb")
err := generateVolume(cfg.DBPath+"/volumedb", cfg.DBPath+"/normaldb")
if err != nil {
panic("generate volume error: " + err.Error())
}
testService, _ := New(&cfg)
return testService
cleanWG.Add(1)
return testService, func() {
go func() {
cleanTestService(testService)
cleanWG.Done()
}()
}
}
func TestService_CreateVolume(t *testing.T) {
@ -59,9 +72,9 @@ func TestService_CreateVolume(t *testing.T) {
testServiceCfg.CodeModePolicies = append(testServiceCfg.CodeModePolicies,
codemode.Policy{ModeName: codemode.EC4P4L2.Name(), Enable: true})
testService := initServiceWithData()
testService.Close()
clear(testService)
testService, _ := initServiceWithData()
cleanTestService(testService) // waiting closed
cleanWG.Done()
// set EC4P4L2 enable=false
for i := range testServiceCfg.CodeModePolicies {
@ -71,19 +84,15 @@ func TestService_CreateVolume(t *testing.T) {
testServiceCfg.CodeModePolicies[i].Enable = true
}
}
testService = initServiceWithData()
defer clear(testService)
defer testService.Close()
_, clean := initServiceWithData()
defer clean()
}
func TestService_VolumeInfo(t *testing.T) {
testService := initServiceWithData()
testService, clean := initServiceWithData()
defer clean()
cmClient := initTestClusterClient(testService)
_, ctx := trace.StartSpanFromContext(context.Background(), "")
defer clear(testService)
defer testService.Close()
ctx := newCtx()
// get volumeInfo
{
@ -150,15 +159,12 @@ func TestService_VolumeInfo(t *testing.T) {
}
func TestService_VolumeAlloc(t *testing.T) {
testService := initServiceWithData()
testService, clean := initServiceWithData()
defer clean()
cmClient := initTestClusterClient(testService)
_, ctx := trace.StartSpanFromContext(context.Background(), "")
defer clear(testService)
defer testService.Close()
ctx := newCtx()
// alloc volume
args := &clustermgr.AllocVolumeArgs{
CodeMode: 1,
Count: 1,
@ -193,12 +199,10 @@ func TestService_VolumeAlloc(t *testing.T) {
func TestService_VolumeAlloc2(t *testing.T) {
testServiceCfg.VolumeMgrConfig.AllocatableDiskLoadThreshold = 10
// initServiceWithData generate disk_id 1-10
testService := initServiceWithData()
testService, clean := initServiceWithData()
defer clean()
cmClient := initTestClusterClient(testService)
_, ctx := trace.StartSpanFromContext(context.Background(), "")
defer clear(testService)
defer testService.Close()
ctx := newCtx()
args := &clustermgr.AllocVolumeArgs{
CodeMode: 1,
@ -216,12 +220,10 @@ func TestService_VolumeAlloc2(t *testing.T) {
}
func TestService_ChunkSetCompact(t *testing.T) {
testService := initServiceWithData()
testService, clean := initServiceWithData()
defer clean()
cmClient := initTestClusterClient(testService)
_, ctx := trace.StartSpanFromContext(context.Background(), "")
defer clear(testService)
defer testService.Close()
ctx := newCtx()
// chunk set compact
{
@ -256,12 +258,10 @@ func TestService_ChunkSetCompact(t *testing.T) {
}
func TestService_UpdateVolume(t *testing.T) {
testService := initServiceWithData()
testService, clean := initServiceWithData()
defer clean()
cmClient := initTestClusterClient(testService)
_, ctx := trace.StartSpanFromContext(context.Background(), "")
defer clear(testService)
defer testService.Close()
ctx := newCtx()
// success case
{
@ -302,12 +302,10 @@ func TestService_UpdateVolume(t *testing.T) {
}
func TestService_VolumeLock(t *testing.T) {
testService := initServiceWithData()
testService, clean := initServiceWithData()
defer clean()
cmClient := initTestClusterClient(testService)
_, ctx := trace.StartSpanFromContext(context.Background(), "")
defer clear(testService)
defer testService.Close()
ctx := newCtx()
// lock volume
{
@ -316,7 +314,6 @@ func TestService_VolumeLock(t *testing.T) {
}
err := cmClient.LockVolume(ctx, args)
require.NoError(t, err)
}
// unlock volume
@ -330,12 +327,10 @@ func TestService_VolumeLock(t *testing.T) {
}
func TestService_VolumeUnitList(t *testing.T) {
testService := initServiceWithData()
testService, clean := initServiceWithData()
defer clean()
cmClient := initTestClusterClient(testService)
_, ctx := trace.StartSpanFromContext(context.Background(), "")
defer clear(testService)
defer testService.Close()
ctx := newCtx()
// list volumeUnits
{
@ -350,32 +345,28 @@ func TestService_VolumeUnitList(t *testing.T) {
}
func TestService_VolumeUnitRelease(t *testing.T) {
testService := initServiceWithData()
testService, clean := initServiceWithData()
defer clean()
cmClient := initTestClusterClient(testService)
_, ctx := trace.StartSpanFromContext(context.Background(), "")
defer clear(testService)
defer testService.Close()
ctx := newCtx()
// release volume unit
{
vuid := proto.EncodeVuid(proto.EncodeVuidPrefix(1, 1), 1)
vol, err := cmClient.GetVolumeInfo(ctx, &clustermgr.GetVolumeArgs{Vid: proto.Vid(1)})
require.NoError(t, err)
oldDiskId := vol.Units[1].DiskID
oldDiskID := vol.Units[1].DiskID
// UT test request to blobnode will return connection refused
err = cmClient.ReleaseVolumeUnit(ctx, &clustermgr.ReleaseVolumeUnitArgs{Vuid: vuid, DiskID: oldDiskId})
err = cmClient.ReleaseVolumeUnit(ctx, &clustermgr.ReleaseVolumeUnitArgs{Vuid: vuid, DiskID: oldDiskID})
require.Error(t, err)
}
}
func TestService_ChunkReport(t *testing.T) {
testService := initServiceWithData()
testService, clean := initServiceWithData()
defer clean()
cmClient := initTestClusterClient(testService)
_, ctx := trace.StartSpanFromContext(context.Background(), "")
defer clear(testService)
defer testService.Close()
ctx := newCtx()
// chunk report
{
@ -396,12 +387,12 @@ func TestService_ChunkReport(t *testing.T) {
}
func TestService_VolumeAllocatedList(t *testing.T) {
testService := initServiceWithData()
cmClient := initTestClusterClient(testService)
_, ctx := trace.StartSpanFromContext(context.Background(), "")
cleanWG.Wait()
defer clear(testService)
defer testService.Close()
testService, clean := initServiceWithData()
defer clean()
cmClient := initTestClusterClient(testService)
ctx := newCtx()
args := &clustermgr.AllocVolumeArgs{
IsInit: false,
@ -429,12 +420,11 @@ func TestService_VolumeAllocatedList(t *testing.T) {
}
func TestService_AdminUpdateVolume(t *testing.T) {
testService := initServiceWithData()
testService, clean := initServiceWithData()
defer clean()
cmClient := initTestClusterClient(testService)
_, ctx := trace.StartSpanFromContext(context.Background(), "")
ctx := newCtx()
defer clear(testService)
defer testService.Close()
args := &clustermgr.VolumeInfoBase{
Vid: 1,
Used: 99,
@ -444,12 +434,11 @@ func TestService_AdminUpdateVolume(t *testing.T) {
}
func TestService_AdminUpdateVolumeUnit(t *testing.T) {
testService := initServiceWithData()
testService, clean := initServiceWithData()
defer clean()
cmClient := initTestClusterClient(testService)
_, ctx := trace.StartSpanFromContext(context.Background(), "")
ctx := newCtx()
defer clear(testService)
defer testService.Close()
args := &clustermgr.AdminUpdateUnitArgs{
Epoch: 3,
NextEpoch: 5,
@ -479,32 +468,30 @@ func TestService_AdminUpdateVolumeUnit(t *testing.T) {
require.Error(t, err)
}
var (
unitCount = 27
tokens = []*volumedb.TokenRecord{}
units = [][]*volumedb.VolumeUnitRecord{}
volumes = []*volumedb.VolumeRecord{}
)
func generateVolume(volumeDBPath, NormalDBPath string) {
func generateVolume(volumeDBPath, NormalDBPath string) error {
var (
unitCount = 27
tokens = []*volumedb.TokenRecord{}
units = [][]*volumedb.VolumeUnitRecord{}
volumes = []*volumedb.VolumeRecord{}
)
volumeDB, err := volumedb.Open(volumeDBPath, false)
if err != nil {
log.Error("open db error")
}
normalDB, err := normaldb.OpenNormalDB(NormalDBPath, false)
if err != nil {
log.Error("open db error")
return err
}
defer volumeDB.Close()
normalDB, err := normaldb.OpenNormalDB(NormalDBPath, false)
if err != nil {
return err
}
defer normalDB.Close()
volTable, err := volumedb.OpenVolumeTable(volumeDB.KVStore)
if err != nil {
log.Error("open volumeTable error, db is nil")
return err
}
for i := 1; i < 11; i++ {
vuidPrefixs := make([]proto.VuidPrefix, unitCount)
unitRecords := make([]*volumedb.VolumeUnitRecord, unitCount)
for j := 0; j < unitCount; j++ {
@ -541,12 +528,12 @@ func generateVolume(volumeDBPath, NormalDBPath string) {
}
err = volTable.PutVolumes(volumes, units, tokens)
if err != nil {
log.Error("put volume error", err)
return err
}
diskTable, err := normaldb.OpenDiskTable(normalDB, true)
if err != nil {
log.Error("open normalTable error,db is nil")
return err
}
for i := 1; i <= unitCount+3; i++ {
dr := &normaldb.DiskInfoRecord{
@ -575,19 +562,18 @@ func generateVolume(volumeDBPath, NormalDBPath string) {
}
err := diskTable.AddDisk(dr)
if err != nil {
log.Error("pur disk record error")
return
return err
}
}
return nil
}
func BenchmarkService_ChunkSetCompact(b *testing.B) {
testService := initServiceWithData()
testService, clean := initServiceWithData()
defer clean()
cmClient := initTestClusterClient(testService)
_, ctx := trace.StartSpanFromContext(context.Background(), "")
defer clear(testService)
defer testService.Close()
ctx := newCtx()
b.ResetTimer()
for i := 1; i < b.N; i++ {
@ -603,12 +589,10 @@ func BenchmarkService_ChunkSetCompact(b *testing.B) {
}
func BenchmarkService_VolumeAlloc(b *testing.B) {
testService := initServiceWithData()
testService, clean := initServiceWithData()
defer clean()
cmClient := initTestClusterClient(testService)
_, ctx := trace.StartSpanFromContext(context.Background(), "")
defer clear(testService)
defer testService.Close()
ctx := newCtx()
args := &clustermgr.AllocVolumeArgs{
CodeMode: 1,
@ -626,12 +610,10 @@ func BenchmarkService_VolumeAlloc(b *testing.B) {
}
func BenchmarkService_VolumeListAndListV2(b *testing.B) {
testService := initServiceWithData()
testService, clean := initServiceWithData()
defer clean()
cmClient := initTestClusterClient(testService)
_, ctx := trace.StartSpanFromContext(context.Background(), "")
defer clear(testService)
defer testService.Close()
ctx := newCtx()
listArgs := &clustermgr.ListVolumeArgs{
Marker: proto.Vid(1),
@ -647,12 +629,10 @@ func BenchmarkService_VolumeListAndListV2(b *testing.B) {
}
func BenchmarkService_ChunkReport(b *testing.B) {
testService := initServiceWithData()
testService, clean := initServiceWithData()
defer clean()
cmClient := initTestClusterClient(testService)
_, ctx := trace.StartSpanFromContext(context.Background(), "")
defer clear(testService)
defer testService.Close()
ctx := newCtx()
var chunks []blobnode.ChunkInfo
for i := 1; i < 11; i++ {

View File

@ -27,6 +27,9 @@ type Config struct {
WalDir string `json:"raft_wal_dir"`
WalSync bool `json:"raft_wal_sync"`
// TickIntervalMs is the milliseconds interval only configure in testing cases.
TickIntervalMs int `json:"-"`
// TickInterval is the interval of timer which check heartbeat and election timeout.
// The default value is 2s.
TickInterval int `json:"tick_interval"`

View File

@ -82,6 +82,9 @@ func NewRaftServer(cfg *Config) (RaftServer, error) {
return nil, err
}
tickInterval := time.Duration(cfg.TickInterval) * time.Second
if cfg.TickIntervalMs > 0 {
tickInterval = time.Duration(cfg.TickIntervalMs) * time.Millisecond
}
proposeTimeout := time.Duration(cfg.ProposeTimeout) * time.Second
snapTimeout := time.Duration(cfg.SnapshotTimeout) * time.Second
rs := &raftServer{

View File

@ -208,6 +208,8 @@ var cfgs = [3]*Config{
TickInterval: 1,
ElectionTick: 3,
Members: members,
TickIntervalMs: 50,
},
{
NodeId: 2,
@ -216,6 +218,8 @@ var cfgs = [3]*Config{
TickInterval: 1,
ElectionTick: 3,
Members: members,
TickIntervalMs: 50,
},
{
NodeId: 3,
@ -224,6 +228,8 @@ var cfgs = [3]*Config{
TickInterval: 1,
ElectionTick: 3,
Members: members,
TickIntervalMs: 50,
},
}