Browse code

Add test TestRestartPolicyWithLiveRestore

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>

Tonis Tiigi authored on 2016/12/28 10:44:38
Showing 1 changed files
... ...
@@ -27,7 +27,7 @@ import (
27 27
 	"github.com/docker/docker/pkg/stringid"
28 28
 	"github.com/docker/docker/pkg/testutil"
29 29
 	icmd "github.com/docker/docker/pkg/testutil/cmd"
30
-	"github.com/docker/go-units"
30
+	units "github.com/docker/go-units"
31 31
 	"github.com/docker/libnetwork/iptables"
32 32
 	"github.com/docker/libtrust"
33 33
 	"github.com/go-check/check"
... ...
@@ -2892,5 +2892,62 @@ func (s *DockerDaemonSuite) TestRemoveContainerAfterLiveRestore(c *check.C) {
2892 2892
 
2893 2893
 	out, err = s.d.Cmd("rm", "top")
2894 2894
 	c.Assert(err, check.IsNil, check.Commentf("Output: %s", out))
2895
+}
2896
+
2897
+// #29598
2898
+func (s *DockerDaemonSuite) TestRestartPolicyWithLiveRestore(c *check.C) {
2899
+	testRequires(c, DaemonIsLinux, SameHostDaemon)
2900
+	s.d.StartWithBusybox(c, "--live-restore")
2901
+
2902
+	out, err := s.d.Cmd("run", "-d", "--restart", "always", "busybox", "top")
2903
+	c.Assert(err, check.IsNil, check.Commentf("output: %s", out))
2904
+	id := strings.TrimSpace(out)
2895 2905
 
2906
+	type state struct {
2907
+		Running   bool
2908
+		StartedAt time.Time
2909
+	}
2910
+	out, err = s.d.Cmd("inspect", "-f", "{{json .State}}", id)
2911
+	c.Assert(err, checker.IsNil, check.Commentf("output: %s", out))
2912
+
2913
+	var origState state
2914
+	err = json.Unmarshal([]byte(strings.TrimSpace(out)), &origState)
2915
+	c.Assert(err, checker.IsNil)
2916
+
2917
+	s.d.Restart(c, "--live-restore")
2918
+
2919
+	pid, err := s.d.Cmd("inspect", "-f", "{{.State.Pid}}", id)
2920
+	c.Assert(err, check.IsNil)
2921
+	pidint, err := strconv.Atoi(strings.TrimSpace(pid))
2922
+	c.Assert(err, check.IsNil)
2923
+	c.Assert(pidint, checker.GreaterThan, 0)
2924
+	c.Assert(syscall.Kill(pidint, syscall.SIGKILL), check.IsNil)
2925
+
2926
+	ticker := time.NewTicker(50 * time.Millisecond)
2927
+	timeout := time.After(10 * time.Second)
2928
+
2929
+	for range ticker.C {
2930
+		select {
2931
+		case <-timeout:
2932
+			c.Fatal("timeout waiting for container restart")
2933
+		default:
2934
+		}
2935
+
2936
+		out, err := s.d.Cmd("inspect", "-f", "{{json .State}}", id)
2937
+		c.Assert(err, checker.IsNil, check.Commentf("output: %s", out))
2938
+
2939
+		var newState state
2940
+		err = json.Unmarshal([]byte(strings.TrimSpace(out)), &newState)
2941
+		c.Assert(err, checker.IsNil)
2942
+
2943
+		if !newState.Running {
2944
+			continue
2945
+		}
2946
+		if newState.StartedAt.After(origState.StartedAt) {
2947
+			break
2948
+		}
2949
+	}
2950
+
2951
+	out, err = s.d.Cmd("stop", id)
2952
+	c.Assert(err, check.IsNil, check.Commentf("output: %s", out))
2896 2953
 }