Signed-off-by: yuexiao-wang <wang.yuexiao@zte.com.cn>
| ... | ... |
@@ -35,7 +35,7 @@ type restartManager struct {
|
| 35 | 35 |
canceled bool |
| 36 | 36 |
} |
| 37 | 37 |
|
| 38 |
-// New returns a new restartmanager based on a policy. |
|
| 38 |
+// New returns a new restartManager based on a policy. |
|
| 39 | 39 |
func New(policy container.RestartPolicy, restartCount int) RestartManager {
|
| 40 | 40 |
return &restartManager{policy: policy, restartCount: restartCount, cancel: make(chan struct{})}
|
| 41 | 41 |
} |
| ... | ... |
@@ -63,7 +63,7 @@ func (rm *restartManager) ShouldRestart(exitCode uint32, hasBeenManuallyStopped |
| 63 | 63 |
} |
| 64 | 64 |
|
| 65 | 65 |
if rm.active {
|
| 66 |
- return false, nil, fmt.Errorf("invalid call on active restartmanager")
|
|
| 66 |
+ return false, nil, fmt.Errorf("invalid call on an active restart manager")
|
|
| 67 | 67 |
} |
| 68 | 68 |
// if the container ran for more than 10s, regardless of status and policy reset the |
| 69 | 69 |
// the timeout back to the default. |
| ... | ... |
@@ -9,26 +9,28 @@ import ( |
| 9 | 9 |
|
| 10 | 10 |
func TestRestartManagerTimeout(t *testing.T) {
|
| 11 | 11 |
rm := New(container.RestartPolicy{Name: "always"}, 0).(*restartManager)
|
| 12 |
- should, _, err := rm.ShouldRestart(0, false, 1*time.Second) |
|
| 12 |
+ var duration = time.Duration(1 * time.Second) |
|
| 13 |
+ should, _, err := rm.ShouldRestart(0, false, duration) |
|
| 13 | 14 |
if err != nil {
|
| 14 | 15 |
t.Fatal(err) |
| 15 | 16 |
} |
| 16 | 17 |
if !should {
|
| 17 | 18 |
t.Fatal("container should be restarted")
|
| 18 | 19 |
} |
| 19 |
- if rm.timeout != 100*time.Millisecond {
|
|
| 20 |
- t.Fatalf("restart manager should have a timeout of 100ms but has %s", rm.timeout)
|
|
| 20 |
+ if rm.timeout != defaultTimeout {
|
|
| 21 |
+ t.Fatalf("restart manager should have a timeout of 100 ms but has %s", rm.timeout)
|
|
| 21 | 22 |
} |
| 22 | 23 |
} |
| 23 | 24 |
|
| 24 | 25 |
func TestRestartManagerTimeoutReset(t *testing.T) {
|
| 25 | 26 |
rm := New(container.RestartPolicy{Name: "always"}, 0).(*restartManager)
|
| 26 | 27 |
rm.timeout = 5 * time.Second |
| 27 |
- _, _, err := rm.ShouldRestart(0, false, 10*time.Second) |
|
| 28 |
+ var duration = time.Duration(10 * time.Second) |
|
| 29 |
+ _, _, err := rm.ShouldRestart(0, false, duration) |
|
| 28 | 30 |
if err != nil {
|
| 29 | 31 |
t.Fatal(err) |
| 30 | 32 |
} |
| 31 |
- if rm.timeout != 100*time.Millisecond {
|
|
| 32 |
- t.Fatalf("restart manager should have a timeout of 100ms but has %s", rm.timeout)
|
|
| 33 |
+ if rm.timeout != defaultTimeout {
|
|
| 34 |
+ t.Fatalf("restart manager should have a timeout of 100 ms but has %s", rm.timeout)
|
|
| 33 | 35 |
} |
| 34 | 36 |
} |