Skip to content
This repository was archived by the owner on Jan 21, 2020. It is now read-only.
Merged
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
16 changes: 13 additions & 3 deletions pkg/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,11 @@ func (m *manager) Start() (<-chan struct{}, error) {
log.Infoln("Manager stopped.")
return

case leader := <-notify:
case leader, open := <-notify:

if !open {
return
}

// This channel has data only when there's been a leadership change.

Expand All @@ -150,11 +154,17 @@ func (m *manager) Start() (<-chan struct{}, error) {
case <-m.stop:

log.Infoln("Stopping..")
m.stop = nil
close(stopWorkQueue)
close(notify)
return

case evt := <-leaderChan:
case evt, open := <-leaderChan:

if !open {
return
}

// This here handles possible duplicated events about leadership and fires only when there
// is a change.

Expand Down Expand Up @@ -198,8 +208,8 @@ func (m *manager) Stop() {
if m.stop == nil {
return
}
m.leader.Stop()
close(m.stop)
m.leader.Stop()
}

func (m *manager) getCurrentState() (GlobalSpec, error) {
Expand Down
13 changes: 13 additions & 0 deletions pkg/manager/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ func testToStruct(m *json.RawMessage) interface{} {
return &o
}

func testCloseAll(c []chan string) {
for _, cc := range c {
close(cc)
}
}

func TestNoCallsToGroupWhenNoLeader(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
Expand All @@ -145,11 +151,15 @@ func TestNoCallsToGroupWhenNoLeader(t *testing.T) {
manager1.Start()
manager2.Start()

testSetLeader(t, leaderChans, "nobody")

manager1.Stop()
manager2.Stop()

stoppable1.Stop()
stoppable2.Stop()

testCloseAll(leaderChans)
}

func TestStartOneLeader(t *testing.T) {
Expand Down Expand Up @@ -209,6 +219,7 @@ func TestStartOneLeader(t *testing.T) {
stoppable1.Stop()
stoppable2.Stop()

testCloseAll(leaderChans)
}

func TestChangeLeadership(t *testing.T) {
Expand Down Expand Up @@ -306,4 +317,6 @@ func TestChangeLeadership(t *testing.T) {

stoppable1.Stop()
stoppable2.Stop()

testCloseAll(leaderChans)
}