Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkg/watch: remove test hook #1327

Merged
merged 1 commit into from
Sep 16, 2014
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 0 additions & 3 deletions pkg/watch/mux.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,10 @@ func (m *Mux) loop() {
m.closeAll()
}

var testHookMuxDistribute = func() {}

// distribute sends event to all watchers. Blocking.
func (m *Mux) distribute(event Event) {
m.lock.Lock()
defer m.lock.Unlock()
testHookMuxDistribute()
for _, w := range m.watchers {
select {
case w.result <- event:
Expand Down
21 changes: 12 additions & 9 deletions pkg/watch/mux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,20 @@ func TestMuxWatcherClose(t *testing.T) {
}

func TestMuxWatcherStopDeadlock(t *testing.T) {
defer func(fn func()) { testHookMuxDistribute = fn }(testHookMuxDistribute)
sig, done := make(chan bool), make(chan bool)
testHookMuxDistribute = func() { sig <- true }
done := make(chan bool)
m := NewMux(0)
go func(w Interface) {
// Imagine this goroutine was receiving from w.ResultChan()
// until it received some signal and stopped watching.
<-sig
w.Stop()
go func(w0, w1 Interface) {
// We know Mux is in the distribute loop once one watcher receives
// an event. Stop the other watcher while distribute is trying to
// send to it.
select {
case <-w0.ResultChan():
w1.Stop()
case <-w1.ResultChan():
w0.Stop()
}
close(done)
}(m.Watch())
}(m.Watch(), m.Watch())
m.Action(Added, &myType{})
select {
case <-time.After(5 * time.Second):
Expand Down