Skip to content

Commit

Permalink
Add another test state to TestSetWatchers.
Browse files Browse the repository at this point in the history
  • Loading branch information
samuel committed Oct 29, 2013
1 parent ab53843 commit 02ca7a1
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions zk/zk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,16 @@ func TestSetWatchers(t *testing.T) {
t.Fatalf("Delete returned error: %+v", err)
}

testPath, err := zk.Create("/gozk-test-2", []byte{}, 0, WorldACL(PermAll))
if err != nil {
t.Fatalf("Create returned: %+v", err)
}

_, _, testEvCh, err := zk.GetW(testPath)
if err != nil {
t.Fatalf("GetW returned: %+v", err)
}

children, stat, childCh, err := zk.ChildrenW("/")
if err != nil {
t.Fatalf("Children returned error: %+v", err)
Expand All @@ -258,15 +268,29 @@ func TestSetWatchers(t *testing.T) {
}

zk.conn.Close()
time.Sleep(time.Millisecond * 50)
if err := zk2.Delete(testPath, -1); err != nil && err != ErrNoNode {
t.Fatalf("Delete returned error: %+v", err)
}
time.Sleep(time.Millisecond * 100)

if path, err := zk2.Create("/gozk-test", []byte{1, 2, 3, 4}, 0, WorldACL(PermAll)); err != nil {
t.Fatalf("Create returned error: %+v", err)
} else if path != "/gozk-test" {
t.Fatalf("Create returned different path '%s' != '/gozk-test'", path)
}

_ = childCh
select {
case ev := <-testEvCh:
if ev.Err != nil {
t.Fatalf("GetW watcher error %+v", ev.Err)
}
if ev.Path != testPath {
t.Fatalf("GetW watcher wrong path %s instead of %s", ev.Path, testPath)
}
case <-time.After(2 * time.Second):
t.Fatal("GetW watcher timed out")
}

select {
case ev := <-childCh:
if ev.Err != nil {
Expand Down

0 comments on commit 02ca7a1

Please sign in to comment.