@@ -171,6 +171,54 @@ def changed(d, stat):
171171
172172 eq_ (args , [None , None ])
173173
174+ def test_no_such_node_for_children_watch (self ):
175+ args = []
176+ path = self .path + '/test_no_such_node_for_children_watch'
177+ update = threading .Event ()
178+
179+ def changed (children ):
180+ args .append (children )
181+ update .set ()
182+
183+ # watch a node which does not exist
184+ children_watch = self .client .ChildrenWatch (path , changed )
185+ eq_ (update .is_set (), False )
186+ eq_ (children_watch ._stopped , True )
187+ eq_ (args , [])
188+
189+ # watch a node which exists
190+ self .client .create (path , b'' )
191+ children_watch = self .client .ChildrenWatch (path , changed )
192+ update .wait (3 )
193+ eq_ (args , [[]])
194+ update .clear ()
195+
196+ # watch changes
197+ self .client .create (path + '/fred' , b'' )
198+ update .wait (3 )
199+ eq_ (args , [[], ['fred' ]])
200+ update .clear ()
201+
202+ # delete children
203+ self .client .delete (path + '/fred' )
204+ update .wait (3 )
205+ eq_ (args , [[], ['fred' ], []])
206+ update .clear ()
207+
208+ # delete watching
209+ self .client .delete (path )
210+
211+ # a hack for waiting the watcher stop
212+ for retry in range (5 ):
213+ if children_watch ._stopped :
214+ break
215+ children_watch ._run_lock .acquire ()
216+ children_watch ._run_lock .release ()
217+ time .sleep (retry / 10.0 )
218+
219+ eq_ (update .is_set (), False )
220+ eq_ (children_watch ._stopped , True )
221+
174222 def test_bad_watch_func2 (self ):
175223 counter = 0
176224
0 commit comments