forked from cerc-io/plugeth
eth/downloader: fix flakey test (#24576)
This commit is contained in:
parent
fd4f60f49b
commit
f252154599
@ -785,26 +785,38 @@ func TestSkeletonSyncRetrievals(t *testing.T) {
|
|||||||
skeleton := newSkeleton(db, peerset, drop, newHookedBackfiller())
|
skeleton := newSkeleton(db, peerset, drop, newHookedBackfiller())
|
||||||
skeleton.Sync(tt.head, true)
|
skeleton.Sync(tt.head, true)
|
||||||
|
|
||||||
|
var progress skeletonProgress
|
||||||
// Wait a bit (bleah) for the initial sync loop to go to idle. This might
|
// Wait a bit (bleah) for the initial sync loop to go to idle. This might
|
||||||
// be either a finish or a never-start hence why there's no event to hook.
|
// be either a finish or a never-start hence why there's no event to hook.
|
||||||
time.Sleep(250 * time.Millisecond)
|
check := func() error {
|
||||||
|
if len(progress.Subchains) != len(tt.midstate) {
|
||||||
|
return fmt.Errorf("test %d, mid state: subchain count mismatch: have %d, want %d", i, len(progress.Subchains), len(tt.midstate))
|
||||||
|
|
||||||
// Check the post-init mid state if it matches the required results
|
}
|
||||||
var progress skeletonProgress
|
for j := 0; j < len(progress.Subchains); j++ {
|
||||||
json.Unmarshal(rawdb.ReadSkeletonSyncStatus(db), &progress)
|
if progress.Subchains[j].Head != tt.midstate[j].Head {
|
||||||
|
return fmt.Errorf("test %d, mid state: subchain %d head mismatch: have %d, want %d", i, j, progress.Subchains[j].Head, tt.midstate[j].Head)
|
||||||
if len(progress.Subchains) != len(tt.midstate) {
|
}
|
||||||
t.Errorf("test %d, mid state: subchain count mismatch: have %d, want %d", i, len(progress.Subchains), len(tt.midstate))
|
if progress.Subchains[j].Tail != tt.midstate[j].Tail {
|
||||||
continue
|
return fmt.Errorf("test %d, mid state: subchain %d tail mismatch: have %d, want %d", i, j, progress.Subchains[j].Tail, tt.midstate[j].Tail)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
for j := 0; j < len(progress.Subchains); j++ {
|
|
||||||
if progress.Subchains[j].Head != tt.midstate[j].Head {
|
waitStart := time.Now()
|
||||||
t.Errorf("test %d, mid state: subchain %d head mismatch: have %d, want %d", i, j, progress.Subchains[j].Head, tt.midstate[j].Head)
|
for waitTime := 20 * time.Millisecond; time.Since(waitStart) < time.Second; waitTime = waitTime * 2 {
|
||||||
}
|
time.Sleep(waitTime)
|
||||||
if progress.Subchains[j].Tail != tt.midstate[j].Tail {
|
// Check the post-init end state if it matches the required results
|
||||||
t.Errorf("test %d, mid state: subchain %d tail mismatch: have %d, want %d", i, j, progress.Subchains[j].Tail, tt.midstate[j].Tail)
|
json.Unmarshal(rawdb.ReadSkeletonSyncStatus(db), &progress)
|
||||||
|
if err := check(); err == nil {
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if err := check(); err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
var served uint64
|
var served uint64
|
||||||
for _, peer := range tt.peers {
|
for _, peer := range tt.peers {
|
||||||
served += atomic.LoadUint64(&peer.served)
|
served += atomic.LoadUint64(&peer.served)
|
||||||
@ -830,23 +842,33 @@ func TestSkeletonSyncRetrievals(t *testing.T) {
|
|||||||
}
|
}
|
||||||
// Wait a bit (bleah) for the second sync loop to go to idle. This might
|
// Wait a bit (bleah) for the second sync loop to go to idle. This might
|
||||||
// be either a finish or a never-start hence why there's no event to hook.
|
// be either a finish or a never-start hence why there's no event to hook.
|
||||||
time.Sleep(250 * time.Millisecond)
|
check = func() error {
|
||||||
|
if len(progress.Subchains) != len(tt.endstate) {
|
||||||
// Check the post-init mid state if it matches the required results
|
return fmt.Errorf("test %d, end state: subchain count mismatch: have %d, want %d", i, len(progress.Subchains), len(tt.endstate))
|
||||||
json.Unmarshal(rawdb.ReadSkeletonSyncStatus(db), &progress)
|
}
|
||||||
|
for j := 0; j < len(progress.Subchains); j++ {
|
||||||
if len(progress.Subchains) != len(tt.endstate) {
|
if progress.Subchains[j].Head != tt.endstate[j].Head {
|
||||||
t.Errorf("test %d, end state: subchain count mismatch: have %d, want %d", i, len(progress.Subchains), len(tt.endstate))
|
return fmt.Errorf("test %d, end state: subchain %d head mismatch: have %d, want %d", i, j, progress.Subchains[j].Head, tt.endstate[j].Head)
|
||||||
continue
|
}
|
||||||
|
if progress.Subchains[j].Tail != tt.endstate[j].Tail {
|
||||||
|
return fmt.Errorf("test %d, end state: subchain %d tail mismatch: have %d, want %d", i, j, progress.Subchains[j].Tail, tt.endstate[j].Tail)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
for j := 0; j < len(progress.Subchains); j++ {
|
waitStart = time.Now()
|
||||||
if progress.Subchains[j].Head != tt.endstate[j].Head {
|
for waitTime := 20 * time.Millisecond; time.Since(waitStart) < time.Second; waitTime = waitTime * 2 {
|
||||||
t.Errorf("test %d, end state: subchain %d head mismatch: have %d, want %d", i, j, progress.Subchains[j].Head, tt.endstate[j].Head)
|
time.Sleep(waitTime)
|
||||||
}
|
// Check the post-init end state if it matches the required results
|
||||||
if progress.Subchains[j].Tail != tt.endstate[j].Tail {
|
json.Unmarshal(rawdb.ReadSkeletonSyncStatus(db), &progress)
|
||||||
t.Errorf("test %d, end state: subchain %d tail mismatch: have %d, want %d", i, j, progress.Subchains[j].Tail, tt.endstate[j].Tail)
|
if err := check(); err == nil {
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if err := check(); err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
// Check that the peers served no more headers than we actually needed
|
// Check that the peers served no more headers than we actually needed
|
||||||
served = 0
|
served = 0
|
||||||
for _, peer := range tt.peers {
|
for _, peer := range tt.peers {
|
||||||
|
Loading…
Reference in New Issue
Block a user