TestDaemonDiscoveryBackendConfigReload behavior
`TestDaemonDiscoveryBackendConfigReload` was doing some wierd things with files, creating a file (directly in `./integration-cli`), removing it, then creating a new file. This is just weird, so fixed it to use a single file, file will go into a temp dir so it doesn't pollute integration-cli. It was also blindly sending a SIGHUP to the daemon process then sleeping for 3 seconds. This is racey, and slow. Change this to look for the daemon-reload event in the event stream. Reload logic is moved to a separate function and blocks (w/ a timeout) waiting for the reload event to fire. Runtime of the test is now ~0.5s on my machine, where as it was a minimum of 3s due to the `time.Sleep` before. Signed-off-by: Brian Goff <cpuguy83@gmail.com> Upstream-commit: 20f99a8634accf54a923982f8c9a3b6719933f74 Component: engine
This commit is contained in:
@ -23,7 +23,6 @@ import (
|
||||
"github.com/docker/docker/pkg/integration/checker"
|
||||
icmd "github.com/docker/docker/pkg/integration/cmd"
|
||||
"github.com/docker/docker/pkg/mount"
|
||||
"github.com/docker/docker/pkg/testutil/tempfile"
|
||||
"github.com/docker/go-units"
|
||||
"github.com/docker/libnetwork/iptables"
|
||||
"github.com/docker/libtrust"
|
||||
@ -2352,32 +2351,42 @@ func (s *DockerSuite) TestDaemonDiscoveryBackendConfigReload(c *check.C) {
|
||||
testRequires(c, SameHostDaemon, DaemonIsLinux)
|
||||
|
||||
// daemon config file
|
||||
tmpfile := tempfile.NewTempFile(c, "config-test", `{ "debug" : false }`)
|
||||
defer tmpfile.Remove()
|
||||
daemonConfig := `{ "debug" : false }`
|
||||
configFile, err := ioutil.TempFile("", "test-daemon-discovery-backend-config-reload-config")
|
||||
c.Assert(err, checker.IsNil, check.Commentf("could not create temp file for config reload"))
|
||||
configFilePath := configFile.Name()
|
||||
defer func() {
|
||||
configFile.Close()
|
||||
os.RemoveAll(configFile.Name())
|
||||
}()
|
||||
|
||||
_, err = configFile.Write([]byte(daemonConfig))
|
||||
c.Assert(err, checker.IsNil)
|
||||
|
||||
d := NewDaemon(c)
|
||||
// --log-level needs to be set so that d.Start() doesn't add --debug causing
|
||||
// a conflict with the config
|
||||
err := d.Start("--config-file", tmpfile.Name(), "--log-level=info")
|
||||
err = d.Start("--config-file", configFilePath, "--log-level=info")
|
||||
c.Assert(err, checker.IsNil)
|
||||
defer d.Stop()
|
||||
|
||||
// daemon config file
|
||||
daemonConfig := `{
|
||||
daemonConfig = `{
|
||||
"cluster-store": "consul://consuladdr:consulport/some/path",
|
||||
"cluster-advertise": "192.168.56.100:0",
|
||||
"debug" : false
|
||||
}`
|
||||
|
||||
os.Remove(tmpfile.Name())
|
||||
configFile, err := os.Create(tmpfile.Name())
|
||||
err = configFile.Truncate(0)
|
||||
c.Assert(err, checker.IsNil)
|
||||
_, err = configFile.Seek(0, os.SEEK_SET)
|
||||
c.Assert(err, checker.IsNil)
|
||||
fmt.Fprintf(configFile, "%s", daemonConfig)
|
||||
configFile.Close()
|
||||
|
||||
syscall.Kill(d.cmd.Process.Pid, syscall.SIGHUP)
|
||||
_, err = configFile.Write([]byte(daemonConfig))
|
||||
c.Assert(err, checker.IsNil)
|
||||
|
||||
time.Sleep(3 * time.Second)
|
||||
err = d.reloadConfig()
|
||||
c.Assert(err, checker.IsNil, check.Commentf("error reloading daemon config"))
|
||||
|
||||
out, err := d.Cmd("info")
|
||||
c.Assert(err, checker.IsNil)
|
||||
|
||||
Reference in New Issue
Block a user