From eaf4285f0a4dca5737d6b964eb35afb782f2171a Mon Sep 17 00:00:00 2001 From: Gealber Morales <48373523+Gealber@users.noreply.github.com> Date: Fri, 23 Aug 2024 12:31:24 +0200 Subject: [PATCH] beacon/light/sync: basic tests for rangeLock (#30269) adds simple tests for lock and firstUnlocked method from rangeLock type --------- Co-authored-by: lightclient --- beacon/light/sync/update_sync_test.go | 28 +++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/beacon/light/sync/update_sync_test.go b/beacon/light/sync/update_sync_test.go index 8329bf28c9..88d573165e 100644 --- a/beacon/light/sync/update_sync_test.go +++ b/beacon/light/sync/update_sync_test.go @@ -201,6 +201,34 @@ func TestUpdateSyncDifferentHeads(t *testing.T) { chain.ExpNextSyncPeriod(t, 17) } +func TestRangeLock(t *testing.T) { + r := make(rangeLock) + + // Lock from 0 to 99. + r.lock(0, 100, 1) + for i := 0; i < 100; i++ { + if v, ok := r[uint64(i)]; v <= 0 || !ok { + t.Fatalf("integer space: %d not locked", i) + } + } + + // Unlock from 0 to 99. + r.lock(0, 100, -1) + for i := 0; i < 100; i++ { + if v, ok := r[uint64(i)]; v > 0 || ok { + t.Fatalf("integer space: %d is locked", i) + } + } + + // Lock from 0 to 99 then unlock from 10 to 59. + r.lock(0, 100, 1) + r.lock(10, 50, -1) + first, count := r.firstUnlocked(0, 100) + if first != 10 || count != 50 { + t.Fatalf("unexpected first: %d or count: %d", first, count) + } +} + func testRespUpdate(request requestWithID) request.Response { var resp RespUpdates if request.request == nil {