mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-19 16:20:53 +00:00
0e99e4af4f
* Update lastUpdated on Set() * Merge branch 'master' into lastupdated * gazelle * Merge branch 'master' into lastupdated * Merge branch 'master' into lastupdated
50 lines
1.1 KiB
Go
50 lines
1.1 KiB
Go
package peerstatus
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/libp2p/go-libp2p-core/peer"
|
|
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
|
)
|
|
|
|
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))
|
|
}
|
|
}
|
|
|
|
func TestLastUpdated(t *testing.T) {
|
|
testID := peer.ID("test")
|
|
status := &pb.Status{
|
|
FinalizedEpoch: 1,
|
|
}
|
|
Set(testID, status)
|
|
firstUpdated := LastUpdated(testID)
|
|
|
|
time.Sleep(100 * time.Millisecond)
|
|
|
|
status = &pb.Status{
|
|
FinalizedEpoch: 2,
|
|
}
|
|
Set(testID, status)
|
|
secondUpdated := LastUpdated(testID)
|
|
|
|
if !secondUpdated.After(firstUpdated) {
|
|
t.Error("lastupdated did not increment on subsequent set")
|
|
}
|
|
}
|