Skip to content

Commit f75beac

Browse files
Gealberlightclient
authored andcommitted
beacon/light/sync: basic tests for rangeLock (ethereum#30269)
adds simple tests for lock and firstUnlocked method from rangeLock type --------- Co-authored-by: lightclient <[email protected]>
1 parent 8b79c41 commit f75beac

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

beacon/light/sync/update_sync_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,34 @@ func TestUpdateSyncDifferentHeads(t *testing.T) {
201201
chain.ExpNextSyncPeriod(t, 17)
202202
}
203203

204+
func TestRangeLock(t *testing.T) {
205+
r := make(rangeLock)
206+
207+
// Lock from 0 to 99.
208+
r.lock(0, 100, 1)
209+
for i := 0; i < 100; i++ {
210+
if v, ok := r[uint64(i)]; v <= 0 || !ok {
211+
t.Fatalf("integer space: %d not locked", i)
212+
}
213+
}
214+
215+
// Unlock from 0 to 99.
216+
r.lock(0, 100, -1)
217+
for i := 0; i < 100; i++ {
218+
if v, ok := r[uint64(i)]; v > 0 || ok {
219+
t.Fatalf("integer space: %d is locked", i)
220+
}
221+
}
222+
223+
// Lock from 0 to 99 then unlock from 10 to 59.
224+
r.lock(0, 100, 1)
225+
r.lock(10, 50, -1)
226+
first, count := r.firstUnlocked(0, 100)
227+
if first != 10 || count != 50 {
228+
t.Fatalf("unexpected first: %d or count: %d", first, count)
229+
}
230+
}
231+
204232
func testRespUpdate(request requestWithID) request.Response {
205233
var resp RespUpdates
206234
if request.request == nil {

0 commit comments

Comments
 (0)