From 0cdfacd55273208aed27ac25c1bcbea259f3f120 Mon Sep 17 00:00:00 2001 From: iurii Date: Mon, 21 Oct 2024 19:31:37 +0300 Subject: [PATCH] check total number of slots requested --- beacon/goclient/attest_test.go | 4 ++++ utils/hashmap/hashmap.go | 3 +++ 2 files changed, 7 insertions(+) diff --git a/beacon/goclient/attest_test.go b/beacon/goclient/attest_test.go index a88d48a268..e3f653e760 100644 --- a/beacon/goclient/attest_test.go +++ b/beacon/goclient/attest_test.go @@ -230,6 +230,8 @@ func TestGoClient_GetAttestationData(t *testing.T) { require.Equal(t, gotResult1c.Target.Epoch, gotResult1a.Target.Epoch) require.Equal(t, gotResult1c.Target.Root, gotResult1a.Target.Root) + uniqueSlots := serverGotRequests.SlowLen() + require.Equal(t, 2, uniqueSlots) reqCntSlot1, ok := serverGotRequests.Get(slot1) require.True(t, ok) require.Equal(t, 1, reqCntSlot1) @@ -300,5 +302,7 @@ func TestGoClient_GetAttestationData(t *testing.T) { reqCnt, _ := serverGotRequests.GetOrSet(slot, 1) require.Equal(t, 1, reqCnt) } + uniqueSlots := serverGotRequests.SlowLen() + require.Equal(t, slotsTotalCnt, uniqueSlots) }) } diff --git a/utils/hashmap/hashmap.go b/utils/hashmap/hashmap.go index 2ec5774c03..8dcf437a1f 100644 --- a/utils/hashmap/hashmap.go +++ b/utils/hashmap/hashmap.go @@ -38,6 +38,9 @@ func (m *Map[Key, Value]) Set(key Key, value Value) { } // SlowLen returns the number of elements in the map by iterating over all items. +// This method call doesn't block other operations (for example Set), hence the +// resulting length value returned might or might not reflect the outcome of +// concurrent operations happening with this Map. // // This implementation is quite expensive. If it becomes a bottleneck, // we should consider maintaining an internal atomic counter and