Browse Source

Merge pull request #4418 from xiang90/ci

pkg/wait: make id checking stricter
Xiang Li 10 years ago
parent
commit
0cdf1c45cf
2 changed files with 23 additions and 6 deletions
  1. 3 0
      pkg/wait/wait.go
  2. 20 6
      pkg/wait/wait_test.go

+ 3 - 0
pkg/wait/wait.go

@@ -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
 }

+ 20 - 6
pkg/wait/wait_test.go

@@ -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) {