mirror of
https://github.com/kemko/nomad.git
synced 2026-01-10 12:25:42 +03:00
Added a test for docker
This commit is contained in:
@@ -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")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user