Signed-off-by: s00318865 <sunyuan3@huawei.com>
| ... | ... |
@@ -214,3 +214,33 @@ func TestRestartPolicyOnFailure(t *testing.T) {
|
| 214 | 214 |
|
| 215 | 215 |
logDone("restart - recording restart policy name for --restart=on-failure")
|
| 216 | 216 |
} |
| 217 |
+ |
|
| 218 |
+// a good container with --restart=on-failure:3 |
|
| 219 |
+// MaximumRetryCount!=0; RestartCount=0 |
|
| 220 |
+func TestContainerRestartwithGoodContainer(t *testing.T) {
|
|
| 221 |
+ defer deleteAllContainers() |
|
| 222 |
+ out, err := exec.Command(dockerBinary, "run", "-d", "--restart=on-failure:3", "busybox", "true").CombinedOutput() |
|
| 223 |
+ if err != nil {
|
|
| 224 |
+ t.Fatal(string(out), err) |
|
| 225 |
+ } |
|
| 226 |
+ id := strings.TrimSpace(string(out)) |
|
| 227 |
+ if err := waitInspect(id, "{{ .State.Restarting }} {{ .State.Running }}", "false false", 5); err != nil {
|
|
| 228 |
+ t.Fatal(err) |
|
| 229 |
+ } |
|
| 230 |
+ count, err := inspectField(id, "RestartCount") |
|
| 231 |
+ if err != nil {
|
|
| 232 |
+ t.Fatal(err) |
|
| 233 |
+ } |
|
| 234 |
+ if count != "0" {
|
|
| 235 |
+ t.Fatalf("Container was restarted %s times, expected %d", count, 0)
|
|
| 236 |
+ } |
|
| 237 |
+ MaximumRetryCount, err := inspectField(id, "HostConfig.RestartPolicy.MaximumRetryCount") |
|
| 238 |
+ if err != nil {
|
|
| 239 |
+ t.Fatal(err) |
|
| 240 |
+ } |
|
| 241 |
+ if MaximumRetryCount != "3" {
|
|
| 242 |
+ t.Fatalf("Container Maximum Retry Count is %s, expected %s", MaximumRetryCount, "3")
|
|
| 243 |
+ } |
|
| 244 |
+ |
|
| 245 |
+ logDone("restart - for a good container with restart policy, MaximumRetryCount is not 0 and RestartCount is 0")
|
|
| 246 |
+} |