Fix peerpool test
With the introduction of the new non-blocking code, events for the peerpool might come out-of-order. That's generally not an issue, but it made tests fail. I have changed the code so that order is more consistent (It's still theoretically possible that a stop signal would arrive out of order in a real scenario, but impact is low and I don't want to change this code too much).
This commit is contained in:
parent
e18050b87f
commit
93bbc9c318
|
@ -322,20 +322,31 @@ func (p *PeerPool) handlePeerEventType(server *p2p.Server, event *p2p.PeerEvent,
|
||||||
p.mu.Lock()
|
p.mu.Lock()
|
||||||
defer p.mu.Unlock()
|
defer p.mu.Unlock()
|
||||||
|
|
||||||
|
var shouldRetry bool
|
||||||
|
var shouldStop bool
|
||||||
switch event.Type {
|
switch event.Type {
|
||||||
case p2p.PeerEventTypeDrop:
|
case p2p.PeerEventTypeDrop:
|
||||||
log.Debug("confirm peer dropped", "ID", event.Peer)
|
log.Debug("confirm peer dropped", "ID", event.Peer)
|
||||||
if p.handleDroppedPeer(server, event.Peer) {
|
if p.handleDroppedPeer(server, event.Peer) {
|
||||||
queueRetry(immediately)
|
shouldRetry = true
|
||||||
}
|
}
|
||||||
case p2p.PeerEventTypeAdd: // skip other events
|
case p2p.PeerEventTypeAdd: // skip other events
|
||||||
log.Debug("confirm peer added", "ID", event.Peer)
|
log.Debug("confirm peer added", "ID", event.Peer)
|
||||||
p.handleAddedPeer(server, event.Peer)
|
p.handleAddedPeer(server, event.Peer)
|
||||||
queueStop()
|
shouldStop = true
|
||||||
default:
|
default:
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// First we send the discovery summary
|
||||||
SendDiscoverySummary(server.PeersInfo())
|
SendDiscoverySummary(server.PeersInfo())
|
||||||
|
|
||||||
|
// then we send the stop event
|
||||||
|
if shouldRetry {
|
||||||
|
queueRetry(immediately)
|
||||||
|
} else if shouldStop {
|
||||||
|
queueStop()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// handleAddedPeer notifies all topics about added peer.
|
// handleAddedPeer notifies all topics about added peer.
|
||||||
|
|
Loading…
Reference in New Issue