open-nomad/client/restarts_test.go
2015-11-05 16:38:19 -08:00

40 lines
985 B
Go

package client
import (
"github.com/hashicorp/nomad/nomad/structs"
"testing"
"time"
)
func TestTaskRunner_ServiceRestartCounter(t *testing.T) {
rt := newRestartTracker(structs.JobTypeService, &structs.RestartPolicy{Attempts: 2, Interval: 2 * time.Minute, Delay: 1 * time.Second})
rt.nextRestart()
rt.nextRestart()
rt.nextRestart()
rt.nextRestart()
rt.nextRestart()
actual, _ := rt.nextRestart()
if !actual {
t.Fatalf("Expect %v, Actual: %v", true, actual)
}
}
func TestTaskRunner_BatchRestartCounter(t *testing.T) {
rt := newRestartTracker(structs.JobTypeBatch, &structs.RestartPolicy{Attempts: 2, Interval: 1 * time.Second, Delay: 1 * time.Second})
rt.nextRestart()
rt.nextRestart()
rt.nextRestart()
rt.nextRestart()
rt.nextRestart()
actual, _ := rt.nextRestart()
if actual {
t.Fatalf("Expect %v, Actual: %v", false, actual)
}
time.Sleep(1 * time.Second)
actual, _ = rt.nextRestart()
if actual {
t.Fatalf("Expect %v, Actual: %v", false, actual)
}
}