diff options
| author | yuexiao-wang <wang.yuexiao@zte.com.cn> | 2016-11-24 22:10:49 +0800 |
|---|---|---|
| committer | yuexiao-wang <wang.yuexiao@zte.com.cn> | 2016-11-25 00:21:58 +0800 |
| commit | 0a0bbab81d30a22e1c60e17c57be09df1541ee9c (patch) | |
| tree | 09aa98e813c2bf5ef91bdbd6707f05f740a00efb /restartmanager | |
| parent | e47ca825d18655851118b12f912ff38bbf285768 (diff) | |
| download | docker-0a0bbab81d30a22e1c60e17c57be09df1541ee9c.tar.gz | |
Optimize the unit test for restartmanager
Signed-off-by: yuexiao-wang <wang.yuexiao@zte.com.cn>
Diffstat (limited to 'restartmanager')
| -rw-r--r-- | restartmanager/restartmanager.go | 4 | ||||
| -rw-r--r-- | restartmanager/restartmanager_test.go | 14 |
2 files changed, 10 insertions, 8 deletions
diff --git a/restartmanager/restartmanager.go b/restartmanager/restartmanager.go index 570fc93802..9d219d9d54 100644 --- a/restartmanager/restartmanager.go +++ b/restartmanager/restartmanager.go @@ -35,7 +35,7 @@ type restartManager struct { canceled bool } -// New returns a new restartmanager based on a policy. +// New returns a new restartManager based on a policy. func New(policy container.RestartPolicy, restartCount int) RestartManager { return &restartManager{policy: policy, restartCount: restartCount, cancel: make(chan struct{})} } @@ -63,7 +63,7 @@ func (rm *restartManager) ShouldRestart(exitCode uint32, hasBeenManuallyStopped } if rm.active { - return false, nil, fmt.Errorf("invalid call on active restartmanager") + return false, nil, fmt.Errorf("invalid call on an active restart manager") } // if the container ran for more than 10s, regardless of status and policy reset the // the timeout back to the default. diff --git a/restartmanager/restartmanager_test.go b/restartmanager/restartmanager_test.go index 20eced54d3..0c91235d7d 100644 --- a/restartmanager/restartmanager_test.go +++ b/restartmanager/restartmanager_test.go @@ -9,26 +9,28 @@ import ( func TestRestartManagerTimeout(t *testing.T) { rm := New(container.RestartPolicy{Name: "always"}, 0).(*restartManager) - should, _, err := rm.ShouldRestart(0, false, 1*time.Second) + var duration = time.Duration(1 * time.Second) + should, _, err := rm.ShouldRestart(0, false, duration) if err != nil { t.Fatal(err) } if !should { t.Fatal("container should be restarted") } - if rm.timeout != 100*time.Millisecond { - t.Fatalf("restart manager should have a timeout of 100ms but has %s", rm.timeout) + if rm.timeout != defaultTimeout { + t.Fatalf("restart manager should have a timeout of 100 ms but has %s", rm.timeout) } } func TestRestartManagerTimeoutReset(t *testing.T) { rm := New(container.RestartPolicy{Name: "always"}, 0).(*restartManager) rm.timeout = 5 * time.Second - _, _, err := rm.ShouldRestart(0, false, 10*time.Second) + var duration = time.Duration(10 * time.Second) + _, _, err := rm.ShouldRestart(0, false, duration) if err != nil { t.Fatal(err) } - if rm.timeout != 100*time.Millisecond { - t.Fatalf("restart manager should have a timeout of 100ms but has %s", rm.timeout) + if rm.timeout != defaultTimeout { + t.Fatalf("restart manager should have a timeout of 100 ms but has %s", rm.timeout) } } |
