From fab8474ef8370a089fe0174e28c197b5b93898df Mon Sep 17 00:00:00 2001 From: guozhao Date: Wed, 18 Jan 2023 16:16:55 +0800 Subject: [PATCH] test: add CompactionSleepInterval in FakeStore's config After setting the ComparionSleepInterval, we can use time.Ticker instead of time.After to optimize the scheduleComparison(), otherwise it will fail in the 'TestStoreCompact(t)' test. Signed-off-by: guozhao --- server/storage/mvcc/kvstore_compaction.go | 5 +++-- server/storage/mvcc/kvstore_test.go | 5 ++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/server/storage/mvcc/kvstore_compaction.go b/server/storage/mvcc/kvstore_compaction.go index 65cbcd7409b..9a0163697a7 100644 --- a/server/storage/mvcc/kvstore_compaction.go +++ b/server/storage/mvcc/kvstore_compaction.go @@ -39,7 +39,8 @@ func (s *store) scheduleCompaction(compactMainRev, prevCompactRev int64) (KeyVal binary.BigEndian.PutUint64(end, uint64(compactMainRev+1)) batchNum := s.cfg.CompactionBatchLimit - batchInterval := s.cfg.CompactionSleepInterval + batchTicker := time.NewTicker(s.cfg.CompactionSleepInterval) + defer batchTicker.Stop() h := newKVHasher(prevCompactRev, compactMainRev, keep) last := make([]byte, 8+1+8) for { @@ -84,7 +85,7 @@ func (s *store) scheduleCompaction(compactMainRev, prevCompactRev int64) (KeyVal dbCompactionPauseMs.Observe(float64(time.Since(start) / time.Millisecond)) select { - case <-time.After(batchInterval): + case <-batchTicker.C: case <-s.stopc: return KeyValueHash{}, fmt.Errorf("interrupted due to stop signal") } diff --git a/server/storage/mvcc/kvstore_test.go b/server/storage/mvcc/kvstore_test.go index 8a8bd5bee6a..c755827ce68 100644 --- a/server/storage/mvcc/kvstore_test.go +++ b/server/storage/mvcc/kvstore_test.go @@ -894,7 +894,10 @@ func newFakeStore(lg *zap.Logger) *store { Recorder: &testutil.RecorderBuffered{}, rangeRespc: make(chan rangeResp, 5)}} s := &store{ - cfg: StoreConfig{CompactionBatchLimit: 10000}, + cfg: StoreConfig{ + CompactionBatchLimit: 10000, + CompactionSleepInterval: minimumBatchInterval, + }, b: b, le: &lease.FakeLessor{}, kvindex: newFakeIndex(),