mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 05:27:21 +00:00
Merge pull request #1327 from abursavich/master
pkg/watch: remove test hook
This commit is contained in:
commit
c47dca5dbb
@ -115,13 +115,10 @@ func (m *Mux) loop() {
|
|||||||
m.closeAll()
|
m.closeAll()
|
||||||
}
|
}
|
||||||
|
|
||||||
var testHookMuxDistribute = func() {}
|
|
||||||
|
|
||||||
// distribute sends event to all watchers. Blocking.
|
// distribute sends event to all watchers. Blocking.
|
||||||
func (m *Mux) distribute(event Event) {
|
func (m *Mux) distribute(event Event) {
|
||||||
m.lock.Lock()
|
m.lock.Lock()
|
||||||
defer m.lock.Unlock()
|
defer m.lock.Unlock()
|
||||||
testHookMuxDistribute()
|
|
||||||
for _, w := range m.watchers {
|
for _, w := range m.watchers {
|
||||||
select {
|
select {
|
||||||
case w.result <- event:
|
case w.result <- event:
|
||||||
|
@ -94,17 +94,20 @@ func TestMuxWatcherClose(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestMuxWatcherStopDeadlock(t *testing.T) {
|
func TestMuxWatcherStopDeadlock(t *testing.T) {
|
||||||
defer func(fn func()) { testHookMuxDistribute = fn }(testHookMuxDistribute)
|
done := make(chan bool)
|
||||||
sig, done := make(chan bool), make(chan bool)
|
|
||||||
testHookMuxDistribute = func() { sig <- true }
|
|
||||||
m := NewMux(0)
|
m := NewMux(0)
|
||||||
go func(w Interface) {
|
go func(w0, w1 Interface) {
|
||||||
// Imagine this goroutine was receiving from w.ResultChan()
|
// We know Mux is in the distribute loop once one watcher receives
|
||||||
// until it received some signal and stopped watching.
|
// an event. Stop the other watcher while distribute is trying to
|
||||||
<-sig
|
// send to it.
|
||||||
w.Stop()
|
select {
|
||||||
|
case <-w0.ResultChan():
|
||||||
|
w1.Stop()
|
||||||
|
case <-w1.ResultChan():
|
||||||
|
w0.Stop()
|
||||||
|
}
|
||||||
close(done)
|
close(done)
|
||||||
}(m.Watch())
|
}(m.Watch(), m.Watch())
|
||||||
m.Action(Added, &myType{})
|
m.Action(Added, &myType{})
|
||||||
select {
|
select {
|
||||||
case <-time.After(5 * time.Second):
|
case <-time.After(5 * time.Second):
|
||||||
|
Loading…
Reference in New Issue
Block a user