Minor cleanup to logic and testsuite.

Signed-off-by: Robert Xu <robxu9@gmail.com>
This commit is contained in:
Robert Xu 2014-06-18 18:47:05 -04:00
parent bc4a4fe09b
commit 7b456a6d6d
5 changed files with 24 additions and 17 deletions

View File

@ -160,7 +160,7 @@ func (s *Server) nodeJoin(me serf.MemberEvent, wan bool) {
addrs := make([]net.Addr, 0) addrs := make([]net.Addr, 0)
for _, member := range members { for _, member := range members {
valid, p := isConsulServer(member) valid, p := isConsulServer(member)
if valid { if valid && p.Datacenter == parts.Datacenter {
if p.Expect != parts.Expect { if p.Expect != parts.Expect {
s.logger.Printf("[ERR] consul: '%v' and '%v' have different expect values. All expect nodes should have the same value, will never leave expect mode", m.Name, member.Name) s.logger.Printf("[ERR] consul: '%v' and '%v' have different expect values. All expect nodes should have the same value, will never leave expect mode", m.Name, member.Name)
return return

View File

@ -234,7 +234,9 @@ func (s *Server) setupSerf(conf *serf.Config, ch chan serf.Event, path string, w
if s.config.Bootstrap { if s.config.Bootstrap {
conf.Tags["bootstrap"] = "1" conf.Tags["bootstrap"] = "1"
} }
if s.config.Expect != 0 {
conf.Tags["expect"] = fmt.Sprintf("%d", s.config.Expect) conf.Tags["expect"] = fmt.Sprintf("%d", s.config.Expect)
}
conf.MemberlistConfig.LogOutput = s.config.LogOutput conf.MemberlistConfig.LogOutput = s.config.LogOutput
conf.LogOutput = s.config.LogOutput conf.LogOutput = s.config.LogOutput
conf.EventCh = ch conf.EventCh = ch

View File

@ -353,7 +353,7 @@ func TestServer_Expect(t *testing.T) {
testutil.WaitForResult(func() (bool, error) { testutil.WaitForResult(func() (bool, error) {
p2, _ = s2.raftPeers.Peers() p2, _ = s2.raftPeers.Peers()
return len(p2) == 0, errors.New(fmt.Sprintf("%v", p1)) return len(p2) == 0, errors.New(fmt.Sprintf("%v", p2))
}, func(err error) { }, func(err error) {
t.Fatalf("should have 0 peers: %v", err) t.Fatalf("should have 0 peers: %v", err)
}) })
@ -375,18 +375,20 @@ func TestServer_Expect(t *testing.T) {
testutil.WaitForResult(func() (bool, error) { testutil.WaitForResult(func() (bool, error) {
p2, _ = s2.raftPeers.Peers() p2, _ = s2.raftPeers.Peers()
return len(p2) == 3, errors.New(fmt.Sprintf("%v", p1)) return len(p2) == 3, errors.New(fmt.Sprintf("%v", p2))
}, func(err error) { }, func(err error) {
t.Fatalf("should have 3 peers: %v", err) t.Fatalf("should have 3 peers: %v", err)
}) })
testutil.WaitForResult(func() (bool, error) { testutil.WaitForResult(func() (bool, error) {
p3, _ = s3.raftPeers.Peers() p3, _ = s3.raftPeers.Peers()
return len(p3) == 3, errors.New(fmt.Sprintf("%v", p1)) return len(p3) == 3, errors.New(fmt.Sprintf("%v", p3))
}, func(err error) { }, func(err error) {
t.Fatalf("should have 3 peers: %v", err) t.Fatalf("should have 3 peers: %v", err)
}) })
// check if there is one leader now
testutil.WaitForLeader(t, s1.RPC, "dc1")
} }
func TestServer_BadExpect(t *testing.T) { func TestServer_BadExpect(t *testing.T) {
@ -425,7 +427,7 @@ func TestServer_BadExpect(t *testing.T) {
testutil.WaitForResult(func() (bool, error) { testutil.WaitForResult(func() (bool, error) {
p2, _ = s2.raftPeers.Peers() p2, _ = s2.raftPeers.Peers()
return len(p2) == 0, errors.New(fmt.Sprintf("%v", p1)) return len(p2) == 0, errors.New(fmt.Sprintf("%v", p2))
}, func(err error) { }, func(err error) {
t.Fatalf("should have 0 peers: %v", err) t.Fatalf("should have 0 peers: %v", err)
}) })
@ -447,14 +449,14 @@ func TestServer_BadExpect(t *testing.T) {
testutil.WaitForResult(func() (bool, error) { testutil.WaitForResult(func() (bool, error) {
p2, _ = s2.raftPeers.Peers() p2, _ = s2.raftPeers.Peers()
return len(p2) == 0, errors.New(fmt.Sprintf("%v", p1)) return len(p2) == 0, errors.New(fmt.Sprintf("%v", p2))
}, func(err error) { }, func(err error) {
t.Fatalf("should have 0 peers: %v", err) t.Fatalf("should have 0 peers: %v", err)
}) })
testutil.WaitForResult(func() (bool, error) { testutil.WaitForResult(func() (bool, error) {
p3, _ = s3.raftPeers.Peers() p3, _ = s3.raftPeers.Peers()
return len(p3) == 0, errors.New(fmt.Sprintf("%v", p1)) return len(p3) == 0, errors.New(fmt.Sprintf("%v", p3))
}, func(err error) { }, func(err error) {
t.Fatalf("should have 0 peers: %v", err) t.Fatalf("should have 0 peers: %v", err)
}) })

View File

@ -86,11 +86,15 @@ func isConsulServer(m serf.Member) (bool, *serverParts) {
datacenter := m.Tags["dc"] datacenter := m.Tags["dc"]
_, bootstrap := m.Tags["bootstrap"] _, bootstrap := m.Tags["bootstrap"]
expect_str := m.Tags["expect"] expect := 0
expect, err := strconv.Atoi(expect_str) expect_str, ok := m.Tags["expect"]
var err error
if ok {
expect, err = strconv.Atoi(expect_str)
if err != nil { if err != nil {
return false, nil return false, nil
} }
}
port_str := m.Tags["port"] port_str := m.Tags["port"]
port, err := strconv.Atoi(port_str) port, err := strconv.Atoi(port_str)

View File

@ -41,7 +41,6 @@ func TestIsConsulServer(t *testing.T) {
Name: "foo", Name: "foo",
Addr: net.IP([]byte{127, 0, 0, 1}), Addr: net.IP([]byte{127, 0, 0, 1}),
Tags: map[string]string{ Tags: map[string]string{
"expect": "0",
"role": "consul", "role": "consul",
"dc": "east-aws", "dc": "east-aws",
"port": "10000", "port": "10000",