storj/satellite/repair/priority_test.go
Moby von Briesen 0ec685b173 satellite/{satellitedb, repair/{queue, checker}}: Use new column "segmentHealth" instead of "numHealthy" in injured segments queue
We plan to add support for a new Reed-Solomon scheme soon, but our
repair queue orders segments by least number of healthy pieces first.
With a second RS scheme, fewer healthy pieces will not necessarily
correlate to lower health.

This change just adds the new column in a migration. A separate change
will add the new health function.

Right now, since we only support one RS scheme, behavior will not
change. Number of healthy pieces is being inserted as "segment health"
until the new health function is merged.

Segment health is calculated with a new priority function created in
commit 3e5640359. In order to use the function, a new config value is
added, called NodeFailureRate, representing the approximate probability
of any individual node going down in the duration of one checker run.

Change-Id: I51c4202203faf52528d923befbe886dbf86d02f2
2020-11-16 21:18:09 +00:00

69 lines
1.8 KiB
Go

// Copyright (C) 2020 Storj Labs, Inc.
// See LICENSE for copying information.
package repair
import (
"math"
"testing"
"github.com/stretchr/testify/assert"
)
func TestBetaI(t *testing.T) {
// check a few places where betaI has some easily representable values
assert.Equal(t, 0.0, betaI(0.5, 5, 0))
assert.Equal(t, 0.0, betaI(1, 3, 0))
assert.Equal(t, 0.0, betaI(8, 10, 0))
assert.Equal(t, 0.0, betaI(8, 10, 0))
assert.InDelta(t, 0.5, betaI(0.5, 0.5, 0.5), epsilon)
assert.InDelta(t, 1.0/3.0, betaI(0.5, 0.5, 0.25), epsilon)
assert.InDelta(t, 0.488, betaI(1, 3, 0.2), epsilon)
}
func BenchmarkBetaI(b *testing.B) {
for i := 0; i < b.N; i++ {
assert.InDelta(b, 1.0/3.0, betaI(0.5, 0.5, 0.25), epsilon)
}
}
func TestSegmentDanger(t *testing.T) {
const failureRate = 0.01
assert.Greater(t,
SegmentDanger(11, 10, failureRate),
SegmentDanger(10, 5, failureRate))
assert.Greater(t,
SegmentDanger(11, 10, failureRate),
SegmentDanger(10, 9, failureRate))
assert.Greater(t,
SegmentDanger(10, 10, failureRate),
SegmentDanger(9, 9, failureRate))
assert.Less(t,
SegmentDanger(11, 10, failureRate),
SegmentDanger(12, 11, failureRate))
}
func TestSegmentHealth(t *testing.T) {
const failureRate = 0.01
assert.Less(t,
SegmentHealth(11, 10, failureRate),
SegmentHealth(10, 5, failureRate))
assert.Less(t,
SegmentHealth(11, 10, failureRate),
SegmentHealth(10, 9, failureRate))
assert.Less(t,
SegmentHealth(10, 10, failureRate),
SegmentHealth(9, 9, failureRate))
assert.Greater(t,
SegmentHealth(11, 10, failureRate),
SegmentHealth(12, 11, failureRate))
assert.Greater(t,
SegmentHealth(13, 10, failureRate),
SegmentHealth(12, 10, failureRate))
}
func TestSegmentHealthForDecayedSegment(t *testing.T) {
const failureRate = 0.01
assert.True(t, math.IsNaN(SegmentHealth(9, 10, failureRate)))
}