From 101224cac5540a8e8dc3a1ac7d5edff9fca64398 Mon Sep 17 00:00:00 2001 From: millken Date: Tue, 11 Jul 2023 15:46:13 +0800 Subject: [PATCH] fix test --- blocksync/blocksync.go | 6 ++++-- blocksync/blocksync_test.go | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/blocksync/blocksync.go b/blocksync/blocksync.go index ad9ccf6db2..76cde98f83 100644 --- a/blocksync/blocksync.go +++ b/blocksync/blocksync.go @@ -183,7 +183,9 @@ func (bs *blockSyncer) flushInfo() (time.Time, uint64) { return bs.lastTipUpdateTime, bs.targetHeight } func (bs *blockSyncer) syncWork() { - bs.sync() + go time.AfterFunc(bs.cfg.RateLimitInterval, func() { + bs.trigger <- struct{}{} + }) for range bs.trigger { time.Sleep(bs.cfg.RateLimitInterval) //limit the frequency of sync bs.sync() @@ -309,7 +311,7 @@ func (bs *blockSyncer) ProcessBlock(ctx context.Context, peer string, blk *block bs.lastTipUpdateTime = time.Now() } requestMaxHeight := atomic.LoadUint64(&bs.requestMaxHeight) - if syncedHeight >= requestMaxHeight && bs.IsReady() { + if requestMaxHeight > 0 && syncedHeight >= requestMaxHeight && bs.IsReady() { bs.trigger <- struct{}{} atomic.SwapUint64(&bs.requestMaxHeight, 0) } diff --git a/blocksync/blocksync_test.go b/blocksync/blocksync_test.go index 37edc83fdb..9a016d2b05 100644 --- a/blocksync/blocksync_test.go +++ b/blocksync/blocksync_test.go @@ -604,7 +604,7 @@ func TestBlockSyncerBugIssue3889(t *testing.T) { } func TestBlockSync(t *testing.T) { - t.SkipNow() + //t.SkipNow() require := require.New(t) cfg := DefaultConfig cfg.Interval = 1 * time.Second