From 93bbc9c318bc0f10ab0c6aa574b576b538fe674a Mon Sep 17 00:00:00 2001 From: Andrea Maria Piana Date: Fri, 5 Feb 2021 14:25:58 +0100 Subject: [PATCH] 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). --- peers/peerpool.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/peers/peerpool.go b/peers/peerpool.go index 143135218..dcf025f24 100644 --- a/peers/peerpool.go +++ b/peers/peerpool.go @@ -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.