Skip to content

Commit

Permalink
Factor out data comparator for storage tests.
Browse files Browse the repository at this point in the history
For influxdb, we are planning to export lesser data. Having a separate
comparator will let us reuse the same tests.

Docker-DCO-1.1-Signed-off-by: Rohit Jnagal <jnagal@google.com> (github: rjnagal)
  • Loading branch information
rjnagal committed Aug 9, 2014
1 parent 16439c0 commit 10d631b
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 63 deletions.
10 changes: 7 additions & 3 deletions storage/cache/memcache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,17 @@ import (
"github.com/google/cadvisor/storage/test"
)

func runStorageTest(f func(storage.StorageDriver, *testing.T), t *testing.T) {
func runStorageTest(f func(test.TestStorageDriver, *testing.T), t *testing.T) {
maxSize := 200

var driver storage.StorageDriver
var testDriver test.TestStorageDriver
testDriver.StatsEq = test.DefaultStatsEq
for N := 10; N < maxSize; N += 10 {
backend := memory.New(N*2, N*2)
driver = MemoryCache(N, N, backend)
f(driver, t)
testDriver.Driver = driver
f(testDriver, t)
}

}
Expand All @@ -54,7 +57,8 @@ func TestPercentiles(t *testing.T) {
N := 100
backend := memory.New(N*2, N*2)
driver := MemoryCache(N, N, backend)
test.StorageDriverTestPercentiles(driver, t)
testDriver := test.TestStorageDriver{Driver: driver, StatsEq: test.DefaultStatsEq}
test.StorageDriverTestPercentiles(testDriver, t)
}

func TestRetrievePartialRecentStats(t *testing.T) {
Expand Down
12 changes: 7 additions & 5 deletions storage/influxdb/influxdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@ import (
"testing"
"time"

"github.com/google/cadvisor/storage"
"github.com/google/cadvisor/storage/test"
influxdb "github.com/influxdb/influxdb/client"
)

func runStorageTest(f func(storage.StorageDriver, *testing.T), t *testing.T) {
func runStorageTest(f func(test.TestStorageDriver, *testing.T), t *testing.T) {
machineName := "machineA"
tablename := "t"
database := "cadvisor"
Expand Down Expand Up @@ -75,8 +74,10 @@ func runStorageTest(f func(storage.StorageDriver, *testing.T), t *testing.T) {
if err != nil {
t.Fatal(err)
}

testDriver := test.TestStorageDriver{Driver: driver, StatsEq: test.DefaultStatsEq}
// generate another container's data on same machine.
test.StorageDriverFillRandomStatsFunc("containerOnSameMachine", 100, driver, t)
test.StorageDriverFillRandomStatsFunc("containerOnSameMachine", 100, testDriver, t)

// generate another container's data on another machine.
driverForAnotherMachine, err := New("machineB",
Expand All @@ -91,8 +92,9 @@ func runStorageTest(f func(storage.StorageDriver, *testing.T), t *testing.T) {
t.Fatal(err)
}
defer driverForAnotherMachine.Close()
test.StorageDriverFillRandomStatsFunc("containerOnAnotherMachine", 100, driverForAnotherMachine, t)
f(driver, t)
testDriverOtherMachine := test.TestStorageDriver{Driver: driverForAnotherMachine, StatsEq: test.DefaultStatsEq}
test.StorageDriverFillRandomStatsFunc("containerOnAnotherMachine", 100, testDriverOtherMachine, t)
f(testDriver, t)
}

func TestSampleCpuUsage(t *testing.T) {
Expand Down
10 changes: 7 additions & 3 deletions storage/memory/memory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,16 @@ import (
"github.com/google/cadvisor/storage/test"
)

func runStorageTest(f func(storage.StorageDriver, *testing.T), t *testing.T) {
func runStorageTest(f func(test.TestStorageDriver, *testing.T), t *testing.T) {
maxSize := 200

var driver storage.StorageDriver
var testDriver test.TestStorageDriver
testDriver.StatsEq = test.DefaultStatsEq
for N := 10; N < maxSize; N += 10 {
driver = New(N, N)
f(driver, t)
testDriver.Driver = driver
f(testDriver, t)
}

}
Expand All @@ -51,7 +54,8 @@ func TestPercentilesWithoutSample(t *testing.T) {
func TestPercentiles(t *testing.T) {
N := 100
driver := New(N, N)
test.StorageDriverTestPercentiles(driver, t)
testDriver := test.TestStorageDriver{Driver: driver, StatsEq: test.DefaultStatsEq}
test.StorageDriverTestPercentiles(testDriver, t)
}

func TestRetrievePartialRecentStats(t *testing.T) {
Expand Down
Loading

0 comments on commit 10d631b

Please sign in to comment.