restartmanager_test.go 888 B

12345678910111213141516171819202122232425262728293031323334
  1. package restartmanager
  2. import (
  3. "testing"
  4. "time"
  5. "github.com/docker/engine-api/types/container"
  6. )
  7. func TestRestartManagerTimeout(t *testing.T) {
  8. rm := New(container.RestartPolicy{Name: "always"}, 0).(*restartManager)
  9. should, _, err := rm.ShouldRestart(0, false, 1*time.Second)
  10. if err != nil {
  11. t.Fatal(err)
  12. }
  13. if !should {
  14. t.Fatal("container should be restarted")
  15. }
  16. if rm.timeout != 100*time.Millisecond {
  17. t.Fatalf("restart manager should have a timeout of 100ms but has %s", rm.timeout)
  18. }
  19. }
  20. func TestRestartManagerTimeoutReset(t *testing.T) {
  21. rm := New(container.RestartPolicy{Name: "always"}, 0).(*restartManager)
  22. rm.timeout = 5 * time.Second
  23. _, _, err := rm.ShouldRestart(0, false, 10*time.Second)
  24. if err != nil {
  25. t.Fatal(err)
  26. }
  27. if rm.timeout != 100*time.Millisecond {
  28. t.Fatalf("restart manager should have a timeout of 100ms but has %s", rm.timeout)
  29. }
  30. }