fix test for behaviour penalty validation

This commit is contained in:
vyzo 2020-05-01 22:17:16 +03:00
parent 972505c7b8
commit 6323982964
2 changed files with 17 additions and 5 deletions

View File

@ -164,10 +164,11 @@ func (p *PeerScoreParams) validate() error {
if p.IPColocationFactorWeight > 0 {
return fmt.Errorf("invalid IPColocationFactorWeight; must be negative (or 0 to disable)")
}
if p.IPColocationFactorWeight < 0 && p.IPColocationFactorThreshold < 1 {
if p.IPColocationFactorWeight != 0 && p.IPColocationFactorThreshold < 1 {
return fmt.Errorf("invalid IPColocationFactorThreshold; must be at least 1")
}
// check the behaviour penalty
if p.BehaviourPenaltyWeight > 0 {
return fmt.Errorf("invalid BehaviourPenaltyWeight; must be negative (or 0 to disable)")
}

View File

@ -153,17 +153,29 @@ func TestPeerScoreParamsValidation(t *testing.T) {
if (&PeerScoreParams{TopicScoreCap: 1, AppSpecificScore: appScore, DecayInterval: time.Second, DecayToZero: 2, IPColocationFactorWeight: -1, IPColocationFactorThreshold: 1}).validate() == nil {
t.Fatal("expected validation error")
}
if (&PeerScoreParams{AppSpecificScore: appScore, DecayInterval: time.Second, DecayToZero: 0.01, BehaviourPenaltyWeight: 1}) == nil {
if (&PeerScoreParams{AppSpecificScore: appScore, DecayInterval: time.Second, DecayToZero: 0.01, BehaviourPenaltyWeight: 1}).validate() == nil {
t.Fatal("expected validation error")
}
if (&PeerScoreParams{AppSpecificScore: appScore, DecayInterval: time.Second, DecayToZero: 0.01, BehaviourPenaltyWeight: -1}) == nil {
if (&PeerScoreParams{AppSpecificScore: appScore, DecayInterval: time.Second, DecayToZero: 0.01, BehaviourPenaltyWeight: -1}).validate() == nil {
t.Fatal("expected validation error")
}
if (&PeerScoreParams{AppSpecificScore: appScore, DecayInterval: time.Second, DecayToZero: 0.01, BehaviourPenaltyWeight: -1, BehaviourPenaltyDecay: 2}) == nil {
if (&PeerScoreParams{AppSpecificScore: appScore, DecayInterval: time.Second, DecayToZero: 0.01, BehaviourPenaltyWeight: -1, BehaviourPenaltyDecay: 2}).validate() == nil {
t.Fatal("expected validation error")
}
// don't use these params in production!
if (&PeerScoreParams{
AppSpecificScore: appScore,
DecayInterval: time.Second,
DecayToZero: 0.01,
IPColocationFactorWeight: -1,
IPColocationFactorThreshold: 1,
BehaviourPenaltyWeight: -1,
BehaviourPenaltyDecay: 0.999,
}).validate() != nil {
t.Fatal("expected validation success")
}
if (&PeerScoreParams{
TopicScoreCap: 1,
AppSpecificScore: appScore,
@ -177,7 +189,6 @@ func TestPeerScoreParamsValidation(t *testing.T) {
t.Fatal("expected validation success")
}
// don't use these params in production!
if (&PeerScoreParams{
TopicScoreCap: 1,
AppSpecificScore: appScore,