Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions memberlist_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -613,17 +613,15 @@ func TestMemberList_ResolveAddr_TCP_First(t *testing.T) {
}

func TestMemberList_Members(t *testing.T) {
n1 := &Node{Name: "test"}
n2 := &Node{Name: "test2"}
n3 := &Node{Name: "test3"}

m := &Memberlist{}
nodes := []*nodeState{
&nodeState{Node: *n1, State: StateAlive},
&nodeState{Node: *n2, State: StateDead},
&nodeState{Node: *n3, State: StateSuspect},
}
m.nodes = nodes
n1 := &Node{Name: "test", State: StateAlive}
n2 := &Node{Name: "test2", State: StateDead}
n3 := &Node{Name: "test3", State: StateSuspect}

m := &Memberlist{nodes: []*nodeState{
{Node: *n1},
{Node: *n2},
{Node: *n3},
}}

members := m.Members()
if !reflect.DeepEqual(members, []*Node{n1, n3}) {
Expand Down
8 changes: 4 additions & 4 deletions net_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -472,12 +472,12 @@ func TestTCPPushPull(t *testing.T) {

m.nodes = append(m.nodes, &nodeState{
Node: Node{
Name: "Test 0",
Addr: net.ParseIP(m.config.BindAddr),
Port: uint16(m.config.BindPort),
Name: "Test 0",
Addr: net.ParseIP(m.config.BindAddr),
Port: uint16(m.config.BindPort),
State: StateSuspect,
},
Incarnation: 0,
State: StateSuspect,
StateChange: time.Now().Add(-1 * time.Second),
})

Expand Down
15 changes: 7 additions & 8 deletions state.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,8 @@ func (n *Node) String() string {
// NodeState is used to manage our state view of another node
type nodeState struct {
Node
Incarnation uint32 // Last known incarnation number
State NodeStateType // Current state
StateChange time.Time // Time last state change happened
Incarnation uint32 // Last known incarnation number
StateChange time.Time // Time last state change happened
}

// Address returns the host:port form of a node's address, suitable for use
Expand Down Expand Up @@ -1006,12 +1005,12 @@ func (m *Memberlist) aliveNode(a *alive, notify chan struct{}, bootstrap bool) {
}
state = &nodeState{
Node: Node{
Name: a.Node,
Addr: a.Addr,
Port: a.Port,
Meta: a.Meta,
Name: a.Node,
Addr: a.Addr,
Port: a.Port,
Meta: a.Meta,
State: StateDead,
},
State: StateDead,
}
if len(a.Vsn) > 5 {
state.PMin = a.Vsn[0]
Expand Down
15 changes: 14 additions & 1 deletion state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1777,7 +1777,17 @@ func TestMemberList_DeadNodeLeft(t *testing.T) {
m.deadNode(&d)

// Read the dead event
<-ch
select {
case leave := <-ch:
if leave.Event != NodeLeave {
t.Fatalf("unexpected event: %v", leave.Event)
}
if leave.Node.State != StateLeft {
t.Fatalf("bad state in node leave event: got %v, want %v", leave.Node.State.metricsString(), StateLeft.metricsString())
}
default:
t.Fatalf("no leave message")
}

state := m.nodeMap[nodeName]
if state.State != StateLeft {
Expand Down Expand Up @@ -1860,6 +1870,9 @@ func TestMemberList_DeadNode(t *testing.T) {
if leave.Event != NodeLeave || leave.Node.Name != "test" {
t.Fatalf("bad node name")
}
if leave.Node.State != StateDead {
t.Fatalf("bad state: got %v, want %v", leave.Node.State.metricsString(), StateDead.metricsString())
}
default:
t.Fatalf("no leave message")
}
Expand Down
38 changes: 19 additions & 19 deletions util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,28 +108,28 @@ func TestRetransmitLimit(t *testing.T) {
func TestShuffleNodes(t *testing.T) {
orig := []*nodeState{
&nodeState{
State: StateDead,
Node: Node{State: StateDead},
},
&nodeState{
State: StateAlive,
Node: Node{State: StateAlive},
},
&nodeState{
State: StateAlive,
Node: Node{State: StateAlive},
},
&nodeState{
State: StateDead,
Node: Node{State: StateDead},
},
&nodeState{
State: StateAlive,
Node: Node{State: StateAlive},
},
&nodeState{
State: StateAlive,
Node: Node{State: StateAlive},
},
&nodeState{
State: StateDead,
Node: Node{State: StateDead},
},
&nodeState{
State: StateAlive,
Node: Node{State: StateAlive},
},
}
nodes := make([]*nodeState, len(orig))
Expand Down Expand Up @@ -168,43 +168,43 @@ func TestPushPullScale(t *testing.T) {
func TestMoveDeadNodes(t *testing.T) {
nodes := []*nodeState{
&nodeState{
State: StateDead,
Node: Node{State: StateDead},
StateChange: time.Now().Add(-20 * time.Second),
},
&nodeState{
State: StateAlive,
Node: Node{State: StateAlive},
StateChange: time.Now().Add(-20 * time.Second),
},
// This dead node should not be moved, as its state changed
// less than the specified GossipToTheDead time ago
&nodeState{
State: StateDead,
Node: Node{State: StateDead},
StateChange: time.Now().Add(-10 * time.Second),
},
// This left node should not be moved, as its state changed
// less than the specified GossipToTheDead time ago
&nodeState{
State: StateLeft,
Node: Node{State: StateLeft},
StateChange: time.Now().Add(-10 * time.Second),
},
&nodeState{
State: StateLeft,
Node: Node{State: StateLeft},
StateChange: time.Now().Add(-20 * time.Second),
},
&nodeState{
State: StateAlive,
Node: Node{State: StateAlive},
StateChange: time.Now().Add(-20 * time.Second),
},
&nodeState{
State: StateDead,
Node: Node{State: StateDead},
StateChange: time.Now().Add(-20 * time.Second),
},
&nodeState{
State: StateAlive,
Node: Node{State: StateAlive},
StateChange: time.Now().Add(-20 * time.Second),
},
&nodeState{
State: StateLeft,
Node: Node{State: StateLeft},
StateChange: time.Now().Add(-20 * time.Second),
},
}
Expand Down Expand Up @@ -254,9 +254,9 @@ func TestKRandomNodes(t *testing.T) {
}
nodes = append(nodes, &nodeState{
Node: Node{
Name: fmt.Sprintf("test%d", i),
Name: fmt.Sprintf("test%d", i),
State: state,
},
State: state,
})
}

Expand Down