mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
fix watcher test and keyword test
This commit is contained in:
parent
8a4b2e83a5
commit
dc2eae8595
@ -5,30 +5,30 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestKeywords(t *testing.T) {
|
func TestKeywords(t *testing.T) {
|
||||||
keyword := CheckKeyword("machines")
|
keyword := CheckKeyword("_etcd")
|
||||||
if !keyword {
|
if !keyword {
|
||||||
t.Fatal("machines should be keyword")
|
t.Fatal("machines should be keyword")
|
||||||
}
|
}
|
||||||
|
|
||||||
keyword = CheckKeyword("/machines")
|
keyword = CheckKeyword("/_etcd")
|
||||||
|
|
||||||
if !keyword {
|
if !keyword {
|
||||||
t.Fatal("/machines should be keyword")
|
t.Fatal("/machines should be keyword")
|
||||||
}
|
}
|
||||||
|
|
||||||
keyword = CheckKeyword("/machines/")
|
keyword = CheckKeyword("/_etcd/")
|
||||||
|
|
||||||
if !keyword {
|
if !keyword {
|
||||||
t.Fatal("/machines/ contains keyword prefix")
|
t.Fatal("/machines/ contains keyword prefix")
|
||||||
}
|
}
|
||||||
|
|
||||||
keyword = CheckKeyword("/machines/node1")
|
keyword = CheckKeyword("/_etcd/node1")
|
||||||
|
|
||||||
if !keyword {
|
if !keyword {
|
||||||
t.Fatal("/machines/* contains keyword prefix")
|
t.Fatal("/machines/* contains keyword prefix")
|
||||||
}
|
}
|
||||||
|
|
||||||
keyword = CheckKeyword("/nokeyword/machines/node1")
|
keyword = CheckKeyword("/nokeyword/_etcd/node1")
|
||||||
|
|
||||||
if keyword {
|
if keyword {
|
||||||
t.Fatal("this does not contain keyword prefix")
|
t.Fatal("this does not contain keyword prefix")
|
||||||
|
@ -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
56
store/watcher_test.go
Normal 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")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user