Skip to content

Commit

Permalink
Merge pull request #4755 from ElrondNetwork/fix_peers_rating_handler_…
Browse files Browse the repository at this point in the history
…decrease_call

Add missing call to DecreaseRating on peersRatingHandler
  • Loading branch information
sstanculeanu committed Dec 8, 2022
2 parents 1dbcfff + 15d5512 commit 348a321
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ func (trs *topicResolverSender) sendOnTopic(
if err != nil {
continue
}
trs.peersRatingHandler.DecreaseRating(peer)

logData = append(logData, peerType)
logData = append(logData, peer.Pretty())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,13 +282,23 @@ func TestTopicResolverSender_SendOnRequestTopicShouldWorkAndNotSendToFullHistory
return []core.PeerID{pID2}
},
}
decreaseCalledCounter := 0
arg.PeersRatingHandler = &p2pmocks.PeersRatingHandlerStub{
DecreaseRatingCalled: func(pid core.PeerID) {
decreaseCalledCounter++
if !bytes.Equal(pid.Bytes(), pID1.Bytes()) && !bytes.Equal(pid.Bytes(), pID2.Bytes()) {
assert.Fail(t, "should be one of the provided pids")
}
},
}
trs, _ := topicResolverSender.NewTopicResolverSender(arg)

err := trs.SendOnRequestTopic(&dataRetriever.RequestData{}, defaultHashes)

assert.Nil(t, err)
assert.True(t, sentToPid1)
assert.True(t, sentToPid2)
assert.Equal(t, 2, decreaseCalledCounter)
}

func TestTopicResolverSender_SendOnRequestTopicShouldWorkAndSendToFullHistoryNodes(t *testing.T) {
Expand Down Expand Up @@ -317,11 +327,19 @@ func TestTopicResolverSender_SendOnRequestTopicShouldWorkAndSendToFullHistoryNod
return false
},
}
decreaseCalledCounter := 0
arg.PeersRatingHandler = &p2pmocks.PeersRatingHandlerStub{
DecreaseRatingCalled: func(pid core.PeerID) {
decreaseCalledCounter++
assert.Equal(t, pIDfullHistory, pid)
},
}
trs, _ := topicResolverSender.NewTopicResolverSender(arg)

err := trs.SendOnRequestTopic(&dataRetriever.RequestData{}, defaultHashes)
assert.Nil(t, err)
assert.True(t, sentToFullHistoryPeer)
assert.Equal(t, 1, decreaseCalledCounter)
}

func TestTopicResolverSender_SendOnRequestTopicShouldWorkAndSendToPreferredPeers(t *testing.T) {
Expand Down

0 comments on commit 348a321

Please sign in to comment.