prysm-pulse/beacon-chain/sync/peerstatus/peer_statuses_test.go
Nishant Das f8c870aa91
Fix Failure Counter (#3850)
* fix bug

* return if not ok

* don't set peer status there

* fix build

* fix test

* fix all other tests

* add regression test

* cosmetic changes
2019-10-29 13:23:55 +08:00

27 lines
631 B
Go

package peerstatus
import (
"testing"
"github.com/libp2p/go-libp2p-core/peer"
)
func TestIncrementFailureCount(t *testing.T) {
testID := peer.ID("test")
IncreaseFailureCount(testID)
if FailureCount(testID) != 1 {
t.Errorf("Wanted failure count of %d but got %d", 1, FailureCount(testID))
}
}
func TestAboveFailureThreshold(t *testing.T) {
testID := peer.ID("test")
for i := 0; i <= maxFailureThreshold; i++ {
IncreaseFailureCount(testID)
}
if !IsBadPeer(testID) {
t.Errorf("Peer isnt considered as a bad peer despite crossing the failure threshold "+
"with a failure count of %d", FailureCount(testID))
}
}