Skip to content

Commit 9e57b69

Browse files
committed
Fix race in test
1 parent 1491216 commit 9e57b69

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

‎lazycache_test.go‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,13 +223,16 @@ func BenchmarkCacheParallel(b *testing.B) {
223223
b.Run("Get", func(b *testing.B) {
224224
cache := New(CacheOptions{MaxEntries: maxSize})
225225
r := rand.New(rand.NewSource(99))
226+
var mu sync.Mutex
226227
numItems := maxSize - 200
227228
for i := 0; i < numItems; i++ {
228229
cache.Set(i, i)
229230
}
230231
b.RunParallel(func(pb *testing.PB) {
231232
for pb.Next() {
233+
mu.Lock()
232234
key := r.Intn(numItems)
235+
mu.Unlock()
233236
v := cache.Get(key)
234237
if v == nil {
235238
b.Fatalf("unexpected nil value for key %d", key)

0 commit comments

Comments
 (0)