diff --git a/store/keyword_test.go b/store/keyword_test.go index 064d0f6de..f2d15565d 100644 --- a/store/keyword_test.go +++ b/store/keyword_test.go @@ -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") diff --git a/store/watcher_test.bak b/store/watcher_test.bak deleted file mode 100644 index ad5e80283..000000000 --- a/store/watcher_test.bak +++ /dev/null @@ -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") - } - -} diff --git a/store/watcher_test.go b/store/watcher_test.go new file mode 100644 index 000000000..77c20e179 --- /dev/null +++ b/store/watcher_test.go @@ -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") + } + } +}