613
618
watch = Watch(1, path, None, True, None)
614
619
self.assertEqual(watch.started, watch._watch_started_deferred)
621
def random_error(self, *args):
622
"""Throw a fake exception."""
623
raise FakeException()
625
@defer.inlineCallbacks
626
def test_start_watching_fails_early_in_thread(self):
627
"""An early failure inside the thread should errback the deferred."""
628
test_path = self.mktemp("test_directory")
629
self.patch(filesystem_notifications, "CreateFileW", self.random_error)
630
watch = Watch(1, test_path, None, True, None)
631
d = watch.start_watching()
632
yield self.assertFailure(d, FakeException)
634
@defer.inlineCallbacks
635
def test_start_watching_fails_late_in_thread(self):
636
"""A late failure inside the thread should errback the deferred."""
637
test_path = self.mktemp("test_directory")
638
self.patch(filesystem_notifications, "ReadDirectoryChangesW",
640
watch = Watch(1, test_path, None, True, None)
641
d = watch.start_watching()
642
yield self.assertFailure(d, FakeException)
644
@defer.inlineCallbacks
645
def test_close_handle_is_called_on_error(self):
646
"""CloseHandle is called when there's an error in the watch thread."""
647
test_path = self.mktemp("test_directory")
649
self.patch(filesystem_notifications, "CloseHandle",
651
self.patch(filesystem_notifications, "ReadDirectoryChangesW",
653
watch = Watch(1, test_path, None, True, None)
654
d = watch.start_watching()
655
yield self.assertFailure(d, FakeException)
656
self.assertEqual(len(close_called), 1)
617
659
class TestWatchManager(BaseTwistedTestCase):
618
660
"""Test the watch manager."""