github.com/rumpl/bof@v23.0.0-rc.2+incompatible/restartmanager/restartmanager_test.go (about) 1 package restartmanager // import "github.com/docker/docker/restartmanager" 2 3 import ( 4 "testing" 5 "time" 6 7 "github.com/docker/docker/api/types/container" 8 ) 9 10 func TestRestartManagerTimeout(t *testing.T) { 11 rm := New(container.RestartPolicy{Name: "always"}, 0).(*restartManager) 12 var duration = 1 * time.Second 13 should, _, err := rm.ShouldRestart(0, false, duration) 14 if err != nil { 15 t.Fatal(err) 16 } 17 if !should { 18 t.Fatal("container should be restarted") 19 } 20 if rm.timeout != defaultTimeout { 21 t.Fatalf("restart manager should have a timeout of 100 ms but has %s", rm.timeout) 22 } 23 } 24 25 func TestRestartManagerTimeoutReset(t *testing.T) { 26 rm := New(container.RestartPolicy{Name: "always"}, 0).(*restartManager) 27 rm.timeout = 5 * time.Second 28 var duration = 10 * time.Second 29 _, _, err := rm.ShouldRestart(0, false, duration) 30 if err != nil { 31 t.Fatal(err) 32 } 33 if rm.timeout != defaultTimeout { 34 t.Fatalf("restart manager should have a timeout of 100 ms but has %s", rm.timeout) 35 } 36 }