mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-18 19:00:46 +00:00
core/rawdb: improve tests
This commit is contained in:
parent
07511b5359
commit
f7866a0118
2 changed files with 25 additions and 0 deletions
|
|
@ -263,6 +263,17 @@ func basicWrite(t *testing.T, newFn func(kinds []string) ethdb.AncientStore) {
|
||||||
|
|
||||||
// Write should work after truncating from tail but over the head
|
// Write should work after truncating from tail but over the head
|
||||||
db.TruncateTail(200)
|
db.TruncateTail(200)
|
||||||
|
head, err := db.Ancients()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Failed to retrieve head ancients %v", err)
|
||||||
|
}
|
||||||
|
tail, err := db.Tail()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Failed to retrieve tail ancients %v", err)
|
||||||
|
}
|
||||||
|
if head != 200 || tail != 200 {
|
||||||
|
t.Fatalf("Ancient head and tail are not expected")
|
||||||
|
}
|
||||||
_, err = db.ModifyAncients(func(op ethdb.AncientWriteOp) error {
|
_, err = db.ModifyAncients(func(op ethdb.AncientWriteOp) error {
|
||||||
offset := uint64(200)
|
offset := uint64(200)
|
||||||
for i := 0; i < 100; i++ {
|
for i := 0; i < 100; i++ {
|
||||||
|
|
@ -278,6 +289,17 @@ func basicWrite(t *testing.T, newFn func(kinds []string) ethdb.AncientStore) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Failed to write ancient data %v", err)
|
t.Fatalf("Failed to write ancient data %v", err)
|
||||||
}
|
}
|
||||||
|
head, err = db.Ancients()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Failed to retrieve head ancients %v", err)
|
||||||
|
}
|
||||||
|
tail, err = db.Tail()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Failed to retrieve tail ancients %v", err)
|
||||||
|
}
|
||||||
|
if head != 300 || tail != 200 {
|
||||||
|
t.Fatalf("Ancient head and tail are not expected")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func nonMutable(t *testing.T, newFn func(kinds []string) ethdb.AncientStore) {
|
func nonMutable(t *testing.T, newFn func(kinds []string) ethdb.AncientStore) {
|
||||||
|
|
|
||||||
|
|
@ -397,6 +397,9 @@ func (f *MemoryFreezer) TruncateTail(tail uint64) (uint64, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
f.tail = tail
|
f.tail = tail
|
||||||
|
if f.items < tail {
|
||||||
|
f.items = tail
|
||||||
|
}
|
||||||
return old, nil
|
return old, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue