chanotify should use interface{} keys

Fixes #79.

Signed-off-by: Burcu Dogan <jbd@golang.org>
This commit is contained in:
Burcu Dogan 2016-01-22 08:15:13 -08:00
parent 85bc51df33
commit bc4f1aae01
4 changed files with 17 additions and 17 deletions

View file

@ -11,8 +11,8 @@ func TestNotifier(t *testing.T) {
s := New()
ch1 := make(chan struct{}, 1)
ch2 := make(chan struct{}, 1)
s.Add(ch1, "1")
s.Add(ch2, "2")
s.Add("1", ch1)
s.Add("2", ch2)
s.m.Lock()
if len(s.doneCh) != 2 {
t.Fatalf("expected 2 channels, got %d", len(s.doneCh))
@ -20,12 +20,12 @@ func TestNotifier(t *testing.T) {
s.m.Unlock()
ch1 <- struct{}{}
id1 := <-s.Chan()
if id1 != "1" {
if id1.(string) != "1" {
t.Fatalf("1 should be spawned, got %s", id1)
}
ch2 <- struct{}{}
id2 := <-s.Chan()
if id2 != "2" {
if id2.(string) != "2" {
t.Fatalf("2 should be spawned, got %s", id2)
}
close(ch1)
@ -43,10 +43,10 @@ func TestConcurrentNotifier(t *testing.T) {
var chs []chan struct{}
for i := 0; i < 8; i++ {
ch := make(chan struct{}, 2)
s.Add(ch, strconv.Itoa(i))
s.Add(strconv.Itoa(i), ch)
chs = append(chs, ch)
}
testCounter := make(map[string]int)
testCounter := make(map[interface{}]int)
done := make(chan struct{})
go func() {
for id := range s.Chan() {
@ -85,7 +85,7 @@ func TestAddToBlocked(t *testing.T) {
go func() {
// give some time to start first select
time.Sleep(1 * time.Second)
s.Add(ch, "1")
s.Add("1", ch)
ch <- struct{}{}
}()
val := <-s.Chan()