From 993675dd4e12eaf5205b6b8decb424c0fe1f4c57 Mon Sep 17 00:00:00 2001 From: Diptanu Choudhury Date: Fri, 27 May 2016 19:08:17 -0700 Subject: [PATCH] Added a test for docker --- client/driver/docker_test.go | 51 +++++++++++++++++++++++- client/driver/executor/executor_linux.go | 3 +- 2 files changed, 51 insertions(+), 3 deletions(-) diff --git a/client/driver/docker_test.go b/client/driver/docker_test.go index 3fb972bdc..703e3e4a2 100644 --- a/client/driver/docker_test.go +++ b/client/driver/docker_test.go @@ -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") + } + +} diff --git a/client/driver/executor/executor_linux.go b/client/driver/executor/executor_linux.go index 43fa4a36f..45f52cb38 100644 --- a/client/driver/executor/executor_linux.go +++ b/client/driver/executor/executor_linux.go @@ -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