fix watcher test and keyword test

release-0.4
Xiang Li 2013-08-04 17:42:28 -07:00
parent 8a4b2e83a5
commit dc2eae8595
3 changed files with 61 additions and 34 deletions

View File

@ -5,30 +5,30 @@ import (
)
func TestKeywords(t *testing.T) {
keyword := CheckKeyword("machines")
keyword := CheckKeyword("_etcd")
if !keyword {
t.Fatal("machines should be keyword")
}
keyword = CheckKeyword("/machines")
keyword = CheckKeyword("/_etcd")
if !keyword {
t.Fatal("/machines should be keyword")
}
keyword = CheckKeyword("/machines/")
keyword = CheckKeyword("/_etcd/")
if !keyword {
t.Fatal("/machines/ contains keyword prefix")
}
keyword = CheckKeyword("/machines/node1")
keyword = CheckKeyword("/_etcd/node1")
if !keyword {
t.Fatal("/machines/* contains keyword prefix")
}
keyword = CheckKeyword("/nokeyword/machines/node1")
keyword = CheckKeyword("/nokeyword/_etcd/node1")
if keyword {
t.Fatal("this does not contain keyword prefix")

View File

@ -1,29 +0,0 @@
package store
import (
"fmt"
"testing"
"time"
)
func TestWatch(t *testing.T) {
// watcher := createWatcher()
c := make(chan Response)
d := make(chan Response)
w.add("/", c)
go say(c)
w.add("/prefix/", d)
go say(d)
s.Set("/prefix/foo", "bar", time.Unix(0, 0))
}
func say(c chan Response) {
result := <-c
if result.Action != -1 {
fmt.Println("yes")
} else {
fmt.Println("no")
}
}

56
store/watcher_test.go Normal file
View File

@ -0,0 +1,56 @@
package store
import (
"fmt"
"testing"
"time"
)
func TestWatch(t *testing.T) {
s := CreateStore(100)
watchers := make([]*Watcher, 10)
for i, _ := range watchers {
// create a new watcher
watchers[i] = NewWatcher()
// add to the watchers list
s.AddWatcher("foo", watchers[i], 0)
}
s.Set("/foo/foo", "bar", time.Unix(0, 0), 1)
for _, watcher := range watchers {
// wait for the notification for any changing
res := <-watcher.C
if res == nil {
t.Fatal("watcher is cleared")
}
}
for i, _ := range watchers {
// create a new watcher
watchers[i] = NewWatcher()
// add to the watchers list
s.AddWatcher("foo/foo/foo", watchers[i], 0)
}
s.watcher.stopWatchers()
for _, watcher := range watchers {
// wait for the notification for any changing
res := <-watcher.C
if res != nil {
t.Fatal("watcher is cleared")
}
}
}