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