storage unit test percentiles

This commit is contained in:
Nan Deng 2014-06-17 20:33:13 -07:00
parent 90ceeacda3
commit e412c042d3
2 changed files with 48 additions and 1 deletions

View File

@ -44,6 +44,12 @@ func TestSamplesWithoutSample(t *testing.T) {
runStorageTest(test.StorageDriverTestSamplesWithoutSample, t)
}
func TestPercentilessWithoutSample(t *testing.T) {
func TestPercentilesWithoutSample(t *testing.T) {
runStorageTest(test.StorageDriverTestPercentilesWithoutSample, t)
}
func TestPercentiles(t *testing.T) {
N := 100
driver := New(N, N)
test.StorageDriverTestPercentiles(driver, t)
}

View File

@ -168,3 +168,44 @@ func StorageDriverTestPercentilesWithoutSample(driver storage.StorageDriver, t *
t.Errorf("There should be no percentiles")
}
}
// The driver must be able to hold more than 100 samples
func StorageDriverTestPercentiles(driver storage.StorageDriver, t *testing.T) {
N := 100
cpuTrace := make([]uint64, N)
memTrace := make([]uint64, N)
for i := 1; i < N+1; i++ {
cpuTrace[i-1] = uint64(i)
memTrace[i-1] = uint64(i)
}
trace := buildTrace(cpuTrace, memTrace, 1*time.Second)
ref := info.ContainerReference{
Name: "container",
}
for _, stats := range trace {
driver.AddStats(ref, stats)
}
percentages := []int{
80,
90,
50,
}
percentiles, err := driver.Percentiles(ref.Name, percentages, percentages)
if err != nil {
t.Fatal(err)
}
for _, s := range percentiles.CpuUsagePercentiles {
// The value is out of the range of tolerance..
if s.Value > uint64(s.Percentage+1) || s.Value < uint64(s.Percentage-1) {
t.Errorf("%v percentile data should be %v, but got %v", s.Percentage, s.Percentage, s.Value)
}
}
for _, s := range percentiles.MemoryUsagePercentiles {
// The value is out of the range of tolerance..
if s.Value > uint64(s.Percentage+1) || s.Value < uint64(s.Percentage-1) {
t.Errorf("%v percentile data should be %v, but got %v", s.Percentage, s.Percentage, s.Value)
}
}
}