From 9ab1589d2d40fdedfaa5f9bbb6589e4acba551dd Mon Sep 17 00:00:00 2001 From: Roy Crihfield Date: Fri, 11 Aug 2023 15:57:58 +0800 Subject: [PATCH] improve test util --- integration/util_test.go | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/integration/util_test.go b/integration/util_test.go index 3f20d19..45ba823 100644 --- a/integration/util_test.go +++ b/integration/util_test.go @@ -6,7 +6,7 @@ import ( type atomicBlockSet struct { blocks map[uint64]struct{} - sync.Mutex + sync.RWMutex } func newBlockSet() *atomicBlockSet { @@ -14,14 +14,10 @@ func newBlockSet() *atomicBlockSet { } func (set *atomicBlockSet) contains(block uint64) bool { - set.Lock() - defer set.Unlock() - for done := range set.blocks { - if done == block { - return true - } - } - return false + set.RLock() + defer set.RUnlock() + _, has := set.blocks[block] + return has } func (set *atomicBlockSet) containsAll(blocks []uint64) bool {