This repository was archived by the owner on Jan 21, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +26
-3
lines changed Expand file tree Collapse file tree 2 files changed +26
-3
lines changed Original file line number Diff line number Diff line change @@ -126,7 +126,11 @@ func (m *manager) Start() (<-chan struct{}, error) {
126
126
log .Infoln ("Manager stopped." )
127
127
return
128
128
129
- case leader := <- notify :
129
+ case leader , open := <- notify :
130
+
131
+ if ! open {
132
+ return
133
+ }
130
134
131
135
// This channel has data only when there's been a leadership change.
132
136
@@ -150,11 +154,17 @@ func (m *manager) Start() (<-chan struct{}, error) {
150
154
case <- m .stop :
151
155
152
156
log .Infoln ("Stopping.." )
157
+ m .stop = nil
153
158
close (stopWorkQueue )
154
159
close (notify )
155
160
return
156
161
157
- case evt := <- leaderChan :
162
+ case evt , open := <- leaderChan :
163
+
164
+ if ! open {
165
+ return
166
+ }
167
+
158
168
// This here handles possible duplicated events about leadership and fires only when there
159
169
// is a change.
160
170
@@ -198,8 +208,8 @@ func (m *manager) Stop() {
198
208
if m .stop == nil {
199
209
return
200
210
}
201
- m .leader .Stop ()
202
211
close (m .stop )
212
+ m .leader .Stop ()
203
213
}
204
214
205
215
func (m * manager ) getCurrentState () (GlobalSpec , error ) {
Original file line number Diff line number Diff line change @@ -121,6 +121,12 @@ func testToStruct(m *json.RawMessage) interface{} {
121
121
return & o
122
122
}
123
123
124
+ func testCloseAll (c []chan string ) {
125
+ for _ , cc := range c {
126
+ close (cc )
127
+ }
128
+ }
129
+
124
130
func TestNoCallsToGroupWhenNoLeader (t * testing.T ) {
125
131
ctrl := gomock .NewController (t )
126
132
defer ctrl .Finish ()
@@ -145,11 +151,15 @@ func TestNoCallsToGroupWhenNoLeader(t *testing.T) {
145
151
manager1 .Start ()
146
152
manager2 .Start ()
147
153
154
+ testSetLeader (t , leaderChans , "nobody" )
155
+
148
156
manager1 .Stop ()
149
157
manager2 .Stop ()
150
158
151
159
stoppable1 .Stop ()
152
160
stoppable2 .Stop ()
161
+
162
+ testCloseAll (leaderChans )
153
163
}
154
164
155
165
func TestStartOneLeader (t * testing.T ) {
@@ -209,6 +219,7 @@ func TestStartOneLeader(t *testing.T) {
209
219
stoppable1 .Stop ()
210
220
stoppable2 .Stop ()
211
221
222
+ testCloseAll (leaderChans )
212
223
}
213
224
214
225
func TestChangeLeadership (t * testing.T ) {
@@ -306,4 +317,6 @@ func TestChangeLeadership(t *testing.T) {
306
317
307
318
stoppable1 .Stop ()
308
319
stoppable2 .Stop ()
320
+
321
+ testCloseAll (leaderChans )
309
322
}
You can’t perform that action at this time.
0 commit comments