From 6a4efbf3b2219b1c4152be38e670b77fc1e3622b Mon Sep 17 00:00:00 2001 From: Alex Dadgar Date: Tue, 15 Nov 2016 15:28:21 -0800 Subject: [PATCH 1/3] Fix TestRetryJoin --- command/agent/agent.go | 2 +- command/agent/command_test.go | 15 ++++++--------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/command/agent/agent.go b/command/agent/agent.go index 5c8399270..e684365f5 100644 --- a/command/agent/agent.go +++ b/command/agent/agent.go @@ -241,7 +241,7 @@ func (a *Agent) clientConfig() (*clientconfig.Config, error) { if a.config.Client.MaxKillTimeout != "" { dur, err := time.ParseDuration(a.config.Client.MaxKillTimeout) if err != nil { - return nil, fmt.Errorf("Error parsing retry interval: %s", err) + return nil, fmt.Errorf("Error parsing max kill timeout: %s", err) } conf.MaxKillTimeout = dur } diff --git a/command/agent/command_test.go b/command/agent/command_test.go index 248ef1185..342390913 100644 --- a/command/agent/command_test.go +++ b/command/agent/command_test.go @@ -80,12 +80,6 @@ func TestRetryJoin(t *testing.T) { defer os.RemoveAll(dir) defer agent.Shutdown() - tmpDir, err := ioutil.TempDir("", "nomad") - if err != nil { - t.Fatalf("err: %s", err) - } - defer os.RemoveAll(tmpDir) - doneCh := make(chan struct{}) shutdownCh := make(chan struct{}) @@ -96,7 +90,11 @@ func TestRetryJoin(t *testing.T) { cmd := &Command{ ShutdownCh: shutdownCh, - Ui: new(cli.MockUi), + Ui: &cli.BasicUi{ + Reader: os.Stdin, + Writer: os.Stdout, + ErrorWriter: os.Stderr, + }, } serfAddr := fmt.Sprintf( @@ -105,8 +103,7 @@ func TestRetryJoin(t *testing.T) { agent.config.Ports.Serf) args := []string{ - "-server", - "-data-dir", tmpDir, + "-dev", "-node", fmt.Sprintf(`"Node %d"`, getPort()), "-retry-join", serfAddr, "-retry-interval", "1s", From cb187ffce618d157e2494c4b5b40d87fb8e56f27 Mon Sep 17 00:00:00 2001 From: Alex Dadgar Date: Tue, 15 Nov 2016 15:49:05 -0800 Subject: [PATCH 2/3] Fix TestRktDriver_PortsMapping and TestAgent_LoadKeyrings --- client/driver/rkt_test.go | 13 ++++++++----- command/agent/agent_test.go | 4 ++++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/client/driver/rkt_test.go b/client/driver/rkt_test.go index ffdbdc1e4..7da23955c 100644 --- a/client/driver/rkt_test.go +++ b/client/driver/rkt_test.go @@ -445,13 +445,16 @@ func TestRktDriver_PortsMapping(t *testing.T) { if handle == nil { t.Fatalf("missing handle") } - defer handle.Kill() + + go func() { + time.Sleep(1 * time.Second) + if err := handle.Kill(); err != nil { + t.Fatalf("Failed to kill handle: %v", err) + } + }() select { - case res := <-handle.WaitCh(): - if !res.Successful() { - t.Fatalf("err: %v", res) - } + case <-handle.WaitCh(): case <-time.After(time.Duration(testutil.TestMultiplier()*15) * time.Second): t.Fatalf("timeout") } diff --git a/command/agent/agent_test.go b/command/agent/agent_test.go index 71283dcef..735dfca97 100644 --- a/command/agent/agent_test.go +++ b/command/agent/agent_test.go @@ -43,6 +43,10 @@ func makeAgent(t testing.TB, cb func(*Config)) (string, *Agent) { config := nomad.DefaultConfig() conf.NomadConfig = config + // Set the data_dir + conf.DataDir = dir + conf.NomadConfig.DataDir = dir + // Bind and set ports conf.BindAddr = "127.0.0.1" conf.Ports = &Ports{ From 3e5bfcdbc4a6ae7114d9f6f0c2650c795b0311da Mon Sep 17 00:00:00 2001 From: Alex Dadgar Date: Tue, 15 Nov 2016 16:27:07 -0800 Subject: [PATCH 3/3] respond to comment --- client/driver/rkt_test.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/client/driver/rkt_test.go b/client/driver/rkt_test.go index 7da23955c..9a3ec06bc 100644 --- a/client/driver/rkt_test.go +++ b/client/driver/rkt_test.go @@ -446,14 +446,17 @@ func TestRktDriver_PortsMapping(t *testing.T) { t.Fatalf("missing handle") } + failCh := make(chan error, 1) go func() { time.Sleep(1 * time.Second) if err := handle.Kill(); err != nil { - t.Fatalf("Failed to kill handle: %v", err) + failCh <- err } }() select { + case err := <-failCh: + t.Fatalf("failed to kill handle: %v", err) case <-handle.WaitCh(): case <-time.After(time.Duration(testutil.TestMultiplier()*15) * time.Second): t.Fatalf("timeout")