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