2016-03-18 18:50:19 +00:00
|
|
|
package restartmanager
|
|
|
|
|
2016-04-18 20:10:15 +00:00
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2016-09-06 18:18:12 +00:00
|
|
|
"github.com/docker/docker/api/types/container"
|
2016-04-18 20:10:15 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestRestartManagerTimeout(t *testing.T) {
|
|
|
|
rm := New(container.RestartPolicy{Name: "always"}, 0).(*restartManager)
|
2016-11-24 14:10:49 +00:00
|
|
|
var duration = time.Duration(1 * time.Second)
|
|
|
|
should, _, err := rm.ShouldRestart(0, false, duration)
|
2016-04-18 20:10:15 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if !should {
|
|
|
|
t.Fatal("container should be restarted")
|
|
|
|
}
|
2016-11-24 14:10:49 +00:00
|
|
|
if rm.timeout != defaultTimeout {
|
|
|
|
t.Fatalf("restart manager should have a timeout of 100 ms but has %s", rm.timeout)
|
2016-04-18 20:10:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRestartManagerTimeoutReset(t *testing.T) {
|
|
|
|
rm := New(container.RestartPolicy{Name: "always"}, 0).(*restartManager)
|
|
|
|
rm.timeout = 5 * time.Second
|
2016-11-24 14:10:49 +00:00
|
|
|
var duration = time.Duration(10 * time.Second)
|
|
|
|
_, _, err := rm.ShouldRestart(0, false, duration)
|
2016-04-18 20:10:15 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2016-11-24 14:10:49 +00:00
|
|
|
if rm.timeout != defaultTimeout {
|
|
|
|
t.Fatalf("restart manager should have a timeout of 100 ms but has %s", rm.timeout)
|
2016-04-18 20:10:15 +00:00
|
|
|
}
|
|
|
|
}
|