From 1fd94082178e8acb10867fa5d3972aaecf05d8df Mon Sep 17 00:00:00 2001 From: Andrey Pechkurov <37772591+puzpuzpuz@users.noreply.github.com> Date: Mon, 30 Aug 2021 11:22:18 +0300 Subject: [PATCH] Clean up tests (#30) --- map_test.go | 30 ++++++++++++++++-------------- mpmcqueue_test.go | 6 +++--- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/map_test.go b/map_test.go index cd500f0..a780406 100644 --- a/map_test.go +++ b/map_test.go @@ -312,18 +312,20 @@ func TestMapResize_CounterLenLimit(t *testing.T) { } func parallelSeqStorer(t *testing.T, m *Map, storeEach, numIters, numEntries int, cdone chan bool) { - for j := 0; j < numEntries; j++ { - if storeEach == 0 || j%storeEach == 0 { - m.Store(strconv.Itoa(j), j) - // Due to atomic snapshots we must see a ""/j pair. - v, ok := m.Load(strconv.Itoa(j)) - if !ok { - t.Errorf("value was not found for %d", j) - break - } - if vi, ok := v.(int); !ok || vi != j { - t.Errorf("value was not expected for %d: %d", j, vi) - break + for i := 0; i < numIters; i++ { + for j := 0; j < numEntries; j++ { + if storeEach == 0 || j%storeEach == 0 { + m.Store(strconv.Itoa(j), j) + // Due to atomic snapshots we must see a ""/j pair. + v, ok := m.Load(strconv.Itoa(j)) + if !ok { + t.Errorf("value was not found for %d", j) + break + } + if vi, ok := v.(int); !ok || vi != j { + t.Errorf("value was not expected for %d: %d", j, vi) + break + } } } } @@ -332,8 +334,8 @@ func parallelSeqStorer(t *testing.T, m *Map, storeEach, numIters, numEntries int func TestMapParallelStores(t *testing.T) { const numStorers = 4 - const numIters = 10_000_000 - const numEntries = 1000 + const numIters = 10_000 + const numEntries = 100 m := NewMap() cdone := make(chan bool) for i := 0; i < numStorers; i++ { diff --git a/mpmcqueue_test.go b/mpmcqueue_test.go index 28ce9d0..57e3399 100644 --- a/mpmcqueue_test.go +++ b/mpmcqueue_test.go @@ -215,9 +215,9 @@ func TestQueueNonBlockingCalls(t *testing.T) { if testing.Short() { n = 1 } - hammerQueueNonBlockingCalls(t, 1, 10*n, n) - hammerQueueNonBlockingCalls(t, 4, 100*n, 2*n) - hammerQueueNonBlockingCalls(t, 8, 1000*n, 4*n) + hammerQueueNonBlockingCalls(t, 1, n, n) + hammerQueueNonBlockingCalls(t, 2, 10*n, 2*n) + hammerQueueNonBlockingCalls(t, 4, 100*n, 4*n) } func benchmarkQueueProdCons(b *testing.B, queueSize, localWork int) {