mirror of
https://github.com/replicatedhq/troubleshoot.git
synced 2026-08-27 00:37:20 +00:00
The included example found P99 latency of 2.6ms. Fio reported P99 latency of 2.5ms with this command: fio --rw=write --ioengine=sync --fdatasync=1 --directory=/var/lib/etcd --size=220m --bs=2300
60 lines
846 B
Go
60 lines
846 B
Go
package collect
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
)
|
|
|
|
func TestGetPercentileIndex(t *testing.T) {
|
|
tests := []struct {
|
|
length int
|
|
p float64
|
|
answer int
|
|
}{
|
|
{
|
|
length: 2,
|
|
p: 0.49,
|
|
answer: 0,
|
|
},
|
|
{
|
|
length: 2,
|
|
p: 0.5,
|
|
answer: 0,
|
|
},
|
|
{
|
|
length: 2,
|
|
p: 0.51,
|
|
answer: 1,
|
|
},
|
|
{
|
|
length: 100,
|
|
p: 0.01,
|
|
answer: 0,
|
|
},
|
|
{
|
|
length: 100,
|
|
p: 0.99,
|
|
answer: 98,
|
|
},
|
|
{
|
|
length: 100,
|
|
p: 0.995,
|
|
answer: 99,
|
|
},
|
|
{
|
|
length: 10000,
|
|
p: 0.999,
|
|
answer: 9989,
|
|
},
|
|
}
|
|
for _, test := range tests {
|
|
name := fmt.Sprintf("(%f, %d) == %d", test.p, test.length, test.answer)
|
|
t.Run(name, func(t *testing.T) {
|
|
output := getPercentileIndex(test.p, test.length)
|
|
if output != test.answer {
|
|
t.Errorf("Got %d, want %d", output, test.answer)
|
|
}
|
|
})
|
|
}
|
|
}
|