validate that TimeInMeshQuantum is non-zero
otherwise we get a division by zero
This commit is contained in:
parent
11ef2a9cf2
commit
61a13a3ed7
|
@ -179,6 +179,9 @@ func (p *TopicScoreParams) validate() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// check P1
|
// check P1
|
||||||
|
if p.TimeInMeshQuantum == 0 {
|
||||||
|
return fmt.Errorf("invalid TimeInMeshQuantum; must be non zero")
|
||||||
|
}
|
||||||
if p.TimeInMeshWeight < 0 {
|
if p.TimeInMeshWeight < 0 {
|
||||||
return fmt.Errorf("invalid TimeInMeshWeight; must be positive (or 0 to disable)")
|
return fmt.Errorf("invalid TimeInMeshWeight; must be positive (or 0 to disable)")
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,10 @@ func TestPeerScoreThresholdsValidation(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTopicScoreParamsValidation(t *testing.T) {
|
func TestTopicScoreParamsValidation(t *testing.T) {
|
||||||
|
if (&TopicScoreParams{}).validate() == nil {
|
||||||
|
t.Fatal("expected validation error")
|
||||||
|
}
|
||||||
|
|
||||||
if (&TopicScoreParams{TopicWeight: -1}).validate() == nil {
|
if (&TopicScoreParams{TopicWeight: -1}).validate() == nil {
|
||||||
t.Fatal("expected validation error")
|
t.Fatal("expected validation error")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue