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:
Andrea Maria Piana 2021-02-05 14:25:58 +01:00
parent e18050b87f
commit 93bbc9c318
1 changed files with 13 additions and 2 deletions

View File

@ -322,20 +322,31 @@ func (p *PeerPool) handlePeerEventType(server *p2p.Server, event *p2p.PeerEvent,
p.mu.Lock()
defer p.mu.Unlock()
var shouldRetry bool
var shouldStop bool
switch event.Type {
case p2p.PeerEventTypeDrop:
log.Debug("confirm peer dropped", "ID", event.Peer)
if p.handleDroppedPeer(server, event.Peer) {
queueRetry(immediately)
shouldRetry = true
}
case p2p.PeerEventTypeAdd: // skip other events
log.Debug("confirm peer added", "ID", event.Peer)
p.handleAddedPeer(server, event.Peer)
queueStop()
shouldStop = true
default:
return
}
// First we send the discovery summary
SendDiscoverySummary(server.PeersInfo())
// then we send the stop event
if shouldRetry {
queueRetry(immediately)
} else if shouldStop {
queueStop()
}
}
// handleAddedPeer notifies all topics about added peer.