mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
pkg/wait: make id checking stricter
Do not allow register with same id.
This commit is contained in:
parent
26f440be7c
commit
d43bd48977
@ -17,6 +17,7 @@
|
||||
package wait
|
||||
|
||||
import (
|
||||
"log"
|
||||
"sync"
|
||||
|
||||
"github.com/coreos/etcd/pkg/testutil"
|
||||
@ -43,6 +44,8 @@ func (w *List) Register(id uint64) <-chan interface{} {
|
||||
if ch == nil {
|
||||
ch = make(chan interface{}, 1)
|
||||
w.m[id] = ch
|
||||
} else {
|
||||
log.Panicf("dup id %x", id)
|
||||
}
|
||||
return ch
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ package wait
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestWait(t *testing.T) {
|
||||
@ -34,17 +35,30 @@ func TestWait(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRegisterDupSuppression(t *testing.T) {
|
||||
func TestRegisterDupPanic(t *testing.T) {
|
||||
const eid = 1
|
||||
wt := New()
|
||||
ch1 := wt.Register(eid)
|
||||
ch2 := wt.Register(eid)
|
||||
|
||||
panicC := make(chan struct{}, 1)
|
||||
|
||||
func() {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
panicC <- struct{}{}
|
||||
}
|
||||
}()
|
||||
wt.Register(eid)
|
||||
}()
|
||||
|
||||
select {
|
||||
case <-panicC:
|
||||
case <-time.After(1 * time.Second):
|
||||
t.Errorf("failed to receive panic")
|
||||
}
|
||||
|
||||
wt.Trigger(eid, "foo")
|
||||
<-ch1
|
||||
g := <-ch2
|
||||
if g != nil {
|
||||
t.Errorf("unexpected non-nil value: %v (%T)", g, g)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTriggerDupSuppression(t *testing.T) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user