def test_start_watching_fails_early_in_thread(self): """An early failure inside the thread should errback the deferred.""" test_path = self.mktemp("test_directory") self.patch(filesystem_notifications, "CreateFileW", self.random_error) watch = Watch(1, test_path, None) d = watch.start_watching() yield self.assertFailure(d, common_tests.FakeException)
def test_stop_watching_fired_when_watch_thread_finishes(self): """The deferred returned is fired when the watch thread finishes.""" test_path = self.mktemp("another_test_directory") watch = Watch(1, test_path, self.mask) yield watch.start_watching() self.assertNotEqual(watch.platform_watch._watch_handle, None) yield watch.stop_watching() self.assertEqual(watch.platform_watch._watch_handle, None)
def test_close_handle_is_called_on_error(self): """CloseHandle is called when there's an error in the watch thread.""" test_path = self.mktemp("test_directory") close_called = [] self.patch(filesystem_notifications, "CreateFileW", lambda *_: None) self.patch(filesystem_notifications, "CloseHandle", close_called.append) self.patch(filesystem_notifications, "ReadDirectoryChangesW", self.random_error) watch = Watch(1, test_path, self.mask) d = watch.start_watching() yield self.assertFailure(d, common_tests.FakeException) self.assertEqual(len(close_called), 1) yield watch.stop_watching()