Fix tracker.Restore test
This commit is contained in:
parent
523a745cf3
commit
eac1d8b517
@ -189,7 +189,7 @@ func (tr *TrackerImpl) Restore(makeIterator iter.IteratorConstructor) (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// force the lower bound path to an even length (required by geth API/HexToKeyBytes)
|
// force the lower bound path to an even length (required by NodeIterator constructor)
|
||||||
if len(recoveredPath)&1 == 1 {
|
if len(recoveredPath)&1 == 1 {
|
||||||
// to avoid skipped nodes, we must rewind by one index
|
// to avoid skipped nodes, we must rewind by one index
|
||||||
recoveredPath = rewindPath(recoveredPath)
|
recoveredPath = rewindPath(recoveredPath)
|
||||||
@ -246,6 +246,7 @@ func (it *Iterator) Next(descend bool) bool {
|
|||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Bounds returns the bounds of the underlying PrefixBoundIterator, if any
|
||||||
func (it *Iterator) Bounds() ([]byte, []byte) {
|
func (it *Iterator) Bounds() ([]byte, []byte) {
|
||||||
if impl, ok := it.NodeIterator.(*iter.PrefixBoundIterator); ok {
|
if impl, ok := it.NodeIterator.(*iter.PrefixBoundIterator); ok {
|
||||||
return impl.Bounds()
|
return impl.Bounds()
|
||||||
|
@ -25,7 +25,6 @@ func TestTracker(t *testing.T) {
|
|||||||
tr := tracker.New(recoveryFile, NumIters)
|
tr := tracker.New(recoveryFile, NumIters)
|
||||||
defer tr.CloseAndSave()
|
defer tr.CloseAndSave()
|
||||||
|
|
||||||
var prevPath []byte
|
|
||||||
count := 0
|
count := 0
|
||||||
nodeit, err := tree.NodeIterator(nil)
|
nodeit, err := tree.NodeIterator(nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -33,9 +32,9 @@ func TestTracker(t *testing.T) {
|
|||||||
}
|
}
|
||||||
for it := tr.Tracked(nodeit); it.Next(true); {
|
for it := tr.Tracked(nodeit); it.Next(true); {
|
||||||
if count == interrupt {
|
if count == interrupt {
|
||||||
return prevPath // tracker rewinds one node to prevent gaps
|
t.Logf("interrupting at: i=%d path=%v", count, it.Path())
|
||||||
|
return it.Path()
|
||||||
}
|
}
|
||||||
prevPath = it.Path()
|
|
||||||
count++
|
count++
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@ -58,9 +57,19 @@ func TestTracker(t *testing.T) {
|
|||||||
if uint(len(its)) != NumIters {
|
if uint(len(its)) != NumIters {
|
||||||
t.Fatalf("expected to restore %d iterators, got %d", NumIters, len(its))
|
t.Fatalf("expected to restore %d iterators, got %d", NumIters, len(its))
|
||||||
}
|
}
|
||||||
|
if !its[0].Next(true) {
|
||||||
|
t.Fatal("iterator ends prematurely after restore")
|
||||||
|
}
|
||||||
|
if !bytes.Equal(failedAt, its[0].Path()) {
|
||||||
|
// Due to the constraint that NodeIterator can only be initialized with an even-length path,
|
||||||
|
// we sometimes rewind an extra node when restoring (e.g. [1 2 0] => [1 2]).
|
||||||
|
if !its[0].Next(true) {
|
||||||
|
t.Fatal("iterator ends prematurely after restore")
|
||||||
|
}
|
||||||
if !bytes.Equal(failedAt, its[0].Path()) {
|
if !bytes.Equal(failedAt, its[0].Path()) {
|
||||||
t.Fatalf("iterator restored to wrong position: expected %v, got %v", failedAt, its[0].Path())
|
t.Fatalf("iterator restored to wrong position: expected %v, got %v", failedAt, its[0].Path())
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if fileExists(recoveryFile) {
|
if fileExists(recoveryFile) {
|
||||||
t.Fatal("recovery file wasn't removed")
|
t.Fatal("recovery file wasn't removed")
|
||||||
|
Loading…
Reference in New Issue
Block a user