mirror of https://github.com/hashicorp/consul
agent: fix TestRetryJoin
parent
7d3467176b
commit
9872475167
|
@ -2,11 +2,11 @@ package agent
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/hashicorp/consul/agent"
|
"github.com/hashicorp/consul/agent"
|
||||||
|
@ -81,43 +81,42 @@ func TestConfigFail(t *testing.T) {
|
||||||
|
|
||||||
func TestRetryJoin(t *testing.T) {
|
func TestRetryJoin(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
t.Skip("fs: skipping tests that use cmd.Run until signal handling is fixed")
|
|
||||||
a := agent.NewTestAgent(t.Name(), "")
|
a := agent.NewTestAgent(t.Name(), "")
|
||||||
defer a.Shutdown()
|
defer a.Shutdown()
|
||||||
|
|
||||||
cfg2 := agent.TestConfig()
|
|
||||||
tmpDir := testutil.TempDir(t, "consul")
|
|
||||||
defer os.RemoveAll(tmpDir)
|
|
||||||
|
|
||||||
doneCh := make(chan struct{})
|
|
||||||
shutdownCh := make(chan struct{})
|
shutdownCh := make(chan struct{})
|
||||||
|
|
||||||
defer func() {
|
var wg sync.WaitGroup
|
||||||
close(shutdownCh)
|
wg.Add(1)
|
||||||
<-doneCh
|
|
||||||
}()
|
|
||||||
|
|
||||||
ui := cli.NewMockUi()
|
|
||||||
cmd := New(ui, "", version.Version, "", "", shutdownCh)
|
|
||||||
|
|
||||||
args := []string{
|
|
||||||
"-server",
|
|
||||||
"-bind", a.Config.BindAddr.String(),
|
|
||||||
"-data-dir", tmpDir,
|
|
||||||
"-node", fmt.Sprintf(`"%s"`, cfg2.NodeName),
|
|
||||||
"-advertise", a.Config.BindAddr.String(),
|
|
||||||
"-retry-join", a.Config.SerfBindAddrLAN.String(),
|
|
||||||
"-retry-interval", "1s",
|
|
||||||
"-retry-join-wan", a.Config.SerfBindAddrWAN.String(),
|
|
||||||
"-retry-interval-wan", "1s",
|
|
||||||
}
|
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
if code := cmd.Run(args); code != 0 {
|
defer wg.Done()
|
||||||
log.Printf("bad: %d", code)
|
|
||||||
|
tmpDir := testutil.TempDir(t, "consul")
|
||||||
|
defer os.RemoveAll(tmpDir)
|
||||||
|
|
||||||
|
args := []string{
|
||||||
|
"-server",
|
||||||
|
"-bind", a.Config.BindAddr.String(),
|
||||||
|
"-data-dir", tmpDir,
|
||||||
|
"-node", "Node 11111111-1111-1111-1111-111111111111",
|
||||||
|
"-node-id", "11111111-1111-1111-1111-111111111111",
|
||||||
|
"-advertise", a.Config.BindAddr.String(),
|
||||||
|
"-retry-join", a.Config.SerfBindAddrLAN.String(),
|
||||||
|
"-retry-interval", "1s",
|
||||||
|
"-retry-join-wan", a.Config.SerfBindAddrWAN.String(),
|
||||||
|
"-retry-interval-wan", "1s",
|
||||||
|
}
|
||||||
|
|
||||||
|
ui := cli.NewMockUi()
|
||||||
|
cmd := New(ui, "", version.Version, "", "", shutdownCh)
|
||||||
|
// closing shutdownCh triggers a SIGINT which triggers shutdown without leave
|
||||||
|
// which will return 1
|
||||||
|
if code := cmd.Run(args); code != 1 {
|
||||||
|
t.Log(ui.ErrorWriter.String())
|
||||||
|
t.Fatalf("bad: %d", code)
|
||||||
}
|
}
|
||||||
close(doneCh)
|
|
||||||
}()
|
}()
|
||||||
|
|
||||||
retry.Run(t, func(r *retry.R) {
|
retry.Run(t, func(r *retry.R) {
|
||||||
if got, want := len(a.LANMembers()), 2; got != want {
|
if got, want := len(a.LANMembers()), 2; got != want {
|
||||||
r.Fatalf("got %d LAN members want %d", got, want)
|
r.Fatalf("got %d LAN members want %d", got, want)
|
||||||
|
@ -126,6 +125,9 @@ func TestRetryJoin(t *testing.T) {
|
||||||
r.Fatalf("got %d WAN members want %d", got, want)
|
r.Fatalf("got %d WAN members want %d", got, want)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
close(shutdownCh)
|
||||||
|
wg.Wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRetryJoinFail(t *testing.T) {
|
func TestRetryJoinFail(t *testing.T) {
|
||||||
|
|
Loading…
Reference in New Issue