Skip to content

Commit

Permalink
Make delete trigger child watchers
Browse files Browse the repository at this point in the history
  • Loading branch information
samuel committed Mar 12, 2014
1 parent 897888e commit 8edc763
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion zk/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ func (c *Conn) recvLoop(conn net.Conn) error {
case EventNodeCreated:
wTypes = append(wTypes, watchTypeExist)
case EventNodeDeleted, EventNodeDataChanged:
wTypes = append(wTypes, watchTypeExist, watchTypeData)
wTypes = append(wTypes, watchTypeExist, watchTypeData, watchTypeChild)
case EventNodeChildrenChanged:
wTypes = append(wTypes, watchTypeChild)
}
Expand Down
27 changes: 27 additions & 0 deletions zk/zk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,33 @@ func TestChildWatch(t *testing.T) {
case _ = <-time.After(time.Second * 2):
t.Fatal("Child watcher timed out")
}

// Delete of the watched node should trigger the watch

children, stat, childCh, err = zk.ChildrenW("/gozk-test")
if err != nil {
t.Fatalf("Children returned error: %+v", err)
} else if stat == nil {
t.Fatal("Children returned nil stat")
} else if len(children) != 0 {
t.Fatal("Children should return 0 children")
}

if err := zk.Delete("/gozk-test", -1); err != nil && err != ErrNoNode {
t.Fatalf("Delete returned error: %+v", err)
}

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

func TestSetWatchers(t *testing.T) {
Expand Down

0 comments on commit 8edc763

Please sign in to comment.