Test fixes

This commit is contained in:
Alex Dadgar 2016-06-12 11:14:17 -07:00
parent fdda90229f
commit b671cd4134
1 changed files with 2 additions and 48 deletions

View File

@ -13,7 +13,6 @@ import (
"github.com/hashicorp/nomad/client/allocdir" "github.com/hashicorp/nomad/client/allocdir"
"github.com/hashicorp/nomad/client/config" "github.com/hashicorp/nomad/client/config"
"github.com/hashicorp/nomad/client/driver" "github.com/hashicorp/nomad/client/driver"
cstructs "github.com/hashicorp/nomad/client/driver/structs"
"github.com/hashicorp/nomad/nomad/mock" "github.com/hashicorp/nomad/nomad/mock"
"github.com/hashicorp/nomad/nomad/structs" "github.com/hashicorp/nomad/nomad/structs"
"github.com/hashicorp/nomad/testutil" "github.com/hashicorp/nomad/testutil"
@ -133,8 +132,8 @@ func TestTaskRunner_Destroy(t *testing.T) {
// Make sure we are collecting afew stats // Make sure we are collecting afew stats
time.Sleep(2 * time.Second) time.Sleep(2 * time.Second)
stats := tr.StatsReporter().ResourceUsage() stats := tr.LatestResourceUsage()
if len(stats) == 0 { if len(stats.Pids) == 0 || stats.ResourceUsage == nil || stats.ResourceUsage.MemoryStats.RSS == 0 {
t.Fatalf("expected task runner to have some stats") t.Fatalf("expected task runner to have some stats")
} }
@ -404,49 +403,4 @@ func TestTaskRunner_Validate_UserEnforcement(t *testing.T) {
if err := tr.validateTask(); err != nil { if err := tr.validateTask(); err != nil {
t.Fatalf("unexpected error: %v", err) t.Fatalf("unexpected error: %v", err)
} }
}
func TestTaskRunnerResouseUsageTS(t *testing.T) {
_, tr := testTaskRunner(false)
t1, _ := time.Parse(time.RFC822, "02 Jan 06 15:03 MST")
t2, _ := time.Parse(time.RFC822, "02 Jan 06 15:05 MST")
t3, _ := time.Parse(time.RFC822, "02 Jan 06 15:06 MST")
t4, _ := time.Parse(time.RFC822, "02 Jan 06 15:07 MST")
t5, _ := time.Parse(time.RFC822, "02 Jan 06 15:08 MST")
ru1 := cstructs.TaskResourceUsage{Timestamp: t1.UnixNano()}
ru2 := cstructs.TaskResourceUsage{Timestamp: t2.UnixNano()}
ru3 := cstructs.TaskResourceUsage{Timestamp: t3.UnixNano()}
ru4 := cstructs.TaskResourceUsage{Timestamp: t4.UnixNano()}
ru5 := cstructs.TaskResourceUsage{Timestamp: t5.UnixNano()}
tr.resourceUsage.Enqueue(&ru1)
tr.resourceUsage.Enqueue(&ru2)
tr.resourceUsage.Enqueue(&ru3)
tr.resourceUsage.Enqueue(&ru4)
tr.resourceUsage.Enqueue(&ru5)
values := tr.ResourceUsageTS(t3.Add(-1 * time.Second).UnixNano())
if len(values) != 3 {
t.Fatalf("expected values: 3, actual: %v", len(values))
}
values = tr.ResourceUsageTS(t3.UnixNano())
if len(values) != 3 {
t.Fatalf("expected values: 3, actual: %v", len(values))
}
begenning, _ := time.Parse(time.RFC822, "01 Jan 1970 00:00 UTC")
values = tr.ResourceUsageTS(begenning.UnixNano())
if len(values) != 5 {
t.Fatalf("expected values: 5, actual: %v", len(values))
}
values = tr.ResourceUsageTS(t5.Add(1 * time.Second).UnixNano())
if len(values) != 0 {
t.Fatalf("expected values: 3, actual: %v", len(values))
}
} }