mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 10:22:23 +00:00
beacon/light/sync: cleanup TestRangeLock
This commit is contained in:
parent
fdce36a2b3
commit
5296755b9e
1 changed files with 6 additions and 12 deletions
|
|
@ -201,34 +201,28 @@ func TestUpdateSyncDifferentHeads(t *testing.T) {
|
||||||
chain.ExpNextSyncPeriod(t, 17)
|
chain.ExpNextSyncPeriod(t, 17)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_lock(t *testing.T) {
|
func TestRangeLock(t *testing.T) {
|
||||||
r := rangeLock{}
|
r := make(rangeLock)
|
||||||
// locking from 0 to 99
|
|
||||||
|
// Lock from 0 to 99.
|
||||||
r.lock(0, 100, 1)
|
r.lock(0, 100, 1)
|
||||||
// check that elements have values > 0
|
|
||||||
for i := 0; i < 100; i++ {
|
for i := 0; i < 100; i++ {
|
||||||
if v, ok := r[uint64(i)]; v <= 0 || !ok {
|
if v, ok := r[uint64(i)]; v <= 0 || !ok {
|
||||||
t.Fatalf("integer space: %d not locked", i)
|
t.Fatalf("integer space: %d not locked", i)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// unlocking from 0 to 99
|
// Unlock from 0 to 99.
|
||||||
r.lock(0, 100, -1)
|
r.lock(0, 100, -1)
|
||||||
// check that elements have values <= 0
|
|
||||||
for i := 0; i < 100; i++ {
|
for i := 0; i < 100; i++ {
|
||||||
if v, ok := r[uint64(i)]; v > 0 || ok {
|
if v, ok := r[uint64(i)]; v > 0 || ok {
|
||||||
t.Fatalf("integer space: %d is locked", i)
|
t.Fatalf("integer space: %d is locked", i)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
func Test_firstUnlocked(t *testing.T) {
|
// Lock from 0 to 99 then unlock from 10 to 59.
|
||||||
r := rangeLock{}
|
|
||||||
// locking from 0 to 99
|
|
||||||
r.lock(0, 100, 1)
|
r.lock(0, 100, 1)
|
||||||
// unlocking from 10 to 59
|
|
||||||
r.lock(10, 50, -1)
|
r.lock(10, 50, -1)
|
||||||
// check first element unlocked
|
|
||||||
first, count := r.firstUnlocked(0, 100)
|
first, count := r.firstUnlocked(0, 100)
|
||||||
if first != 10 || count != 50 {
|
if first != 10 || count != 50 {
|
||||||
t.Fatalf("unexpected first: %d or count: %d", first, count)
|
t.Fatalf("unexpected first: %d or count: %d", first, count)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue