Skip to content

Commit

Permalink
no curry
Browse files Browse the repository at this point in the history
  • Loading branch information
monnand committed Jul 2, 2014
1 parent 562a150 commit 41dcf6d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 28 deletions.
8 changes: 3 additions & 5 deletions storage/influxdb/influxdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ import (
)

func runStorageTest(f func(storage.StorageDriver, *testing.T), t *testing.T) {
// randomly generate a machine name to mimic multi-machine senario.
machineName := "machine-A"
machineName := "machineA"
tablename := "t"
database := "cadvisor"
username := "root"
Expand Down Expand Up @@ -65,7 +64,7 @@ func runStorageTest(f func(storage.StorageDriver, *testing.T), t *testing.T) {
t.Fatal(err)
}
// generate another container's data on same machine.
test.StorageDriverFillRandomStatsFunc("containerOnSameMachine", 100)(driver, t)
test.StorageDriverFillRandomStatsFunc("containerOnSameMachine", 100, driver, t)

// generate another container's data on another machine.
driverForAnotherMachine, err := New("machineB",
Expand All @@ -80,7 +79,7 @@ func runStorageTest(f func(storage.StorageDriver, *testing.T), t *testing.T) {
t.Fatal(err)
}
defer driverForAnotherMachine.Close()
test.StorageDriverFillRandomStatsFunc("containerOnAnotherMachine", 100)(driverForAnotherMachine, t)
test.StorageDriverFillRandomStatsFunc("containerOnAnotherMachine", 100, driverForAnotherMachine, t)
f(driver, t)
}

Expand All @@ -105,6 +104,5 @@ func TestNoRecentStats(t *testing.T) {
}

func TestNoSamples(t *testing.T) {
runStorageTest(test.StorageDriverFillRandomStatsFunc("otherContainer", 100), t)
runStorageTest(test.StorageDriverTestNoSamples, t)
}
45 changes: 22 additions & 23 deletions storage/test/storagetests.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,36 +83,35 @@ func samplesInTrace(samples []*info.ContainerStatsSample, cpuTrace, memTrace []u
}
}

// This function returns a function that will generate random stats and write
// them into the storage. The returned function will not close the driver of
// the call, which could be served as a building block to do other works
// This function will generate random stats and write
// them into the storage. The function will not close the driver
func StorageDriverFillRandomStatsFunc(
containerName string,
N int,
) func(driver storage.StorageDriver, t *testing.T) {
return func(driver storage.StorageDriver, t *testing.T) {
cpuTrace := make([]uint64, 0, N)
memTrace := make([]uint64, 0, N)

// We need N+1 observations to get N samples
for i := 0; i < N+1; i++ {
cpuTrace = append(cpuTrace, uint64(rand.Intn(1000)))
memTrace = append(memTrace, uint64(rand.Intn(1000)))
}
driver storage.StorageDriver,
t *testing.T,
) {
cpuTrace := make([]uint64, 0, N)
memTrace := make([]uint64, 0, N)

samplePeriod := 1 * time.Second
// We need N+1 observations to get N samples
for i := 0; i < N+1; i++ {
cpuTrace = append(cpuTrace, uint64(rand.Intn(1000)))
memTrace = append(memTrace, uint64(rand.Intn(1000)))
}

ref := info.ContainerReference{
Name: containerName,
}
samplePeriod := 1 * time.Second

trace := buildTrace(cpuTrace, memTrace, samplePeriod)
ref := info.ContainerReference{
Name: containerName,
}

for _, stats := range trace {
err := driver.AddStats(ref, stats)
if err != nil {
t.Fatalf("unable to add stats: %v", err)
}
trace := buildTrace(cpuTrace, memTrace, samplePeriod)

for _, stats := range trace {
err := driver.AddStats(ref, stats)
if err != nil {
t.Fatalf("unable to add stats: %v", err)
}
}
}
Expand Down

0 comments on commit 41dcf6d

Please sign in to comment.