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