mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
swarm/pss: WaitTillSnapshotLoaded() fixed
This commit is contained in:
parent
f322700b23
commit
1d7aa22424
2 changed files with 36 additions and 6 deletions
|
|
@ -101,7 +101,7 @@ func (s *Simulation) kademlias() (ks map[enode.ID]*network.Kademlia) {
|
|||
|
||||
func (s *Simulation) WaitTillSnapshotRecreated(ctx context.Context, snap simulations.Snapshot) error {
|
||||
expected := listSnapshotConnections(snap.Conns)
|
||||
ticker := time.NewTicker(256 * time.Millisecond) // todo: reduce
|
||||
ticker := time.NewTicker(16 * time.Millisecond)
|
||||
defer ticker.Stop()
|
||||
|
||||
for {
|
||||
|
|
@ -125,6 +125,9 @@ func (s *Simulation) listActualConnections() (res []uint64) {
|
|||
return true
|
||||
})
|
||||
}
|
||||
|
||||
// only list those connections that appear twice (both peers should recognize connection as active)
|
||||
res = removeDuplicatesAndSingletons(res)
|
||||
return res
|
||||
}
|
||||
|
||||
|
|
@ -154,15 +157,41 @@ func isAllDeployed(expected []uint64, actual []uint64) bool {
|
|||
// remove value c from exp
|
||||
for i := 0; i < len(exp); i++ {
|
||||
if exp[i] == c {
|
||||
last := len(exp) - 1
|
||||
if last == 0 {
|
||||
exp = removeListElement(exp, i)
|
||||
if len(exp) == 0 {
|
||||
return true
|
||||
}
|
||||
exp[i] = exp[last]
|
||||
exp = exp[:last]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return len(exp) == 0
|
||||
}
|
||||
|
||||
func removeListElement(arr []uint64, i int) []uint64 {
|
||||
last := len(arr)-1
|
||||
arr[i] = arr[last]
|
||||
arr = arr[:last]
|
||||
return arr
|
||||
}
|
||||
|
||||
func removeDuplicatesAndSingletons(arr []uint64) []uint64 {
|
||||
for i := 0; i < len(arr); {
|
||||
found := false
|
||||
for j := i+1; j < len(arr); j++ {
|
||||
if arr[i] == arr[j] {
|
||||
arr = removeListElement(arr, j) // remove duplicate
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if found {
|
||||
i++
|
||||
} else {
|
||||
arr = removeListElement(arr, i) // remove singleton
|
||||
}
|
||||
}
|
||||
|
||||
return arr
|
||||
}
|
||||
|
|
|
|||
|
|
@ -76,6 +76,7 @@ func resetTestVariables() {
|
|||
maxMessages = 0
|
||||
msgCnt = 0
|
||||
msgs = nil
|
||||
sim = nil
|
||||
|
||||
kademlias = make(map[enode.ID]*network.Kademlia)
|
||||
nodeAddrs = make(map[enode.ID][]byte)
|
||||
|
|
@ -165,7 +166,7 @@ func assingTestVariables(sim *simulation.Simulation, msgCount int) {
|
|||
|
||||
if po >= depth {
|
||||
maxMessages++
|
||||
allowed[i] = append(recipients[i], nod.ID())
|
||||
allowed[i] = append(allowed[i], nod.ID())
|
||||
allowedMsgs[nod.ID()] = append(allowedMsgs[nod.ID()], uint64(i))
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue