github.com/akerouanton/docker@v1.11.0-rc3/integration-cli/docker_cli_daemon_not_experimental_test.go (about)

     1  // +build daemon,!windows,!experimental
     2  
     3  package main
     4  
     5  import (
     6  	"io/ioutil"
     7  	"os"
     8  	"strings"
     9  
    10  	"github.com/go-check/check"
    11  )
    12  
    13  // os.Kill should kill daemon ungracefully, leaving behind container mounts.
    14  // A subsequent daemon restart shoud clean up said mounts.
    15  func (s *DockerDaemonSuite) TestCleanupMountsAfterDaemonKill(c *check.C) {
    16  	c.Assert(s.d.StartWithBusybox(), check.IsNil)
    17  
    18  	out, err := s.d.Cmd("run", "-d", "busybox", "top")
    19  	c.Assert(err, check.IsNil, check.Commentf("Output: %s", out))
    20  	id := strings.TrimSpace(out)
    21  	c.Assert(s.d.cmd.Process.Signal(os.Kill), check.IsNil)
    22  	mountOut, err := ioutil.ReadFile("/proc/self/mountinfo")
    23  	c.Assert(err, check.IsNil, check.Commentf("Output: %s", mountOut))
    24  
    25  	// container mounts should exist even after daemon has crashed.
    26  	comment := check.Commentf("%s should stay mounted from older daemon start:\nDaemon root repository %s\n%s", id, s.d.folder, mountOut)
    27  	c.Assert(strings.Contains(string(mountOut), id), check.Equals, true, comment)
    28  
    29  	// restart daemon.
    30  	if err := s.d.Restart(); err != nil {
    31  		c.Fatal(err)
    32  	}
    33  
    34  	// Now, container mounts should be gone.
    35  	mountOut, err = ioutil.ReadFile("/proc/self/mountinfo")
    36  	c.Assert(err, check.IsNil, check.Commentf("Output: %s", mountOut))
    37  	comment = check.Commentf("%s is still mounted from older daemon start:\nDaemon root repository %s\n%s", id, s.d.folder, mountOut)
    38  	c.Assert(strings.Contains(string(mountOut), id), check.Equals, false, comment)
    39  }