Added a test for docker

This commit is contained in:
Diptanu Choudhury
2016-05-27 19:08:17 -07:00
parent 0782803543
commit 993675dd4e
2 changed files with 51 additions and 3 deletions

View File

@@ -143,7 +143,7 @@ func TestDockerDriver_Handle(t *testing.T) {
containerID: "containerid",
killTimeout: 5 * time.Nanosecond,
maxKillTimeout: 15 * time.Nanosecond,
doneCh: make(chan struct{}),
doneCh: make(chan bool),
waitCh: make(chan *cstructs.WaitResult, 1),
}
@@ -816,3 +816,52 @@ func TestDockerDriver_CleanupContainer(t *testing.T) {
}
}
func TestDockerDriver_Stats(t *testing.T) {
t.Parallel()
task := &structs.Task{
Name: "sleep",
Config: map[string]interface{}{
"image": "busybox",
"command": "/bin/sleep",
"args": []string{"100"},
},
LogConfig: &structs.LogConfig{
MaxFiles: 10,
MaxFileSizeMB: 10,
},
Resources: basicResources,
}
_, handle, cleanup := dockerSetup(t, task)
defer cleanup()
go func() {
fmt.Println("GOING TO SLEEP")
time.Sleep(3 * time.Second)
fmt.Println("COMING OUT OF SLEEP")
ru, err := handle.Stats()
fmt.Printf("STATS CALL OVER ru: %#v, err: %v", ru, err)
if err != nil {
t.Fatalf("err: %v", err)
}
if ru.ResourceUsage == nil {
handle.Kill()
t.Fatalf("expected resource usage")
}
err = handle.Kill()
if err != nil {
t.Fatalf("err: %v", err)
}
}()
select {
case res := <-handle.WaitCh():
if res.Successful() {
t.Fatalf("should err: %v", res)
}
case <-time.After(time.Duration(tu.TestMultiplier()*10) * time.Second):
t.Fatalf("timeout")
}
}

View File

@@ -179,9 +179,8 @@ func (e *UniversalExecutor) Stats() (*cstructs.TaskResourceUsage, error) {
ResourceUsage: &cstructs.ResourceUsage{
MemoryStats: ms,
CpuStats: cs,
Timestamp: ts,
},
Timestamp: ts,
Timestamp: ts.UTC().UnixNano(),
}
if pidStats, err := e.pidStats(); err == nil {
taskResUsage.Pids = pidStats