~nataliabidart/ubuntuone-client/login-email-password-for-everyone

« back to all changes in this revision

Viewing changes to tests/platform/windows/test_filesystem_notifications.py

  • Committer: Tarmac
  • Author(s): Alejandro J. Cura
  • Date: 2011-08-11 22:23:15 UTC
  • mfrom: (1102.2.2 errback-watches)
  • Revision ID: tarmac-20110811222315-2umlc26vtbmpxd7y
Catch all errors inside the watch thread. (LP: #824817)

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
    IN_OPEN,
33
33
    IN_CLOSE_WRITE
34
34
)
 
35
from ubuntuone.platform.windows import filesystem_notifications
35
36
from ubuntuone.platform.windows.filesystem_notifications import (
36
37
    FilesystemMonitor,
37
38
    NotifyProcessor,
47
48
)
48
49
 
49
50
 
 
51
class FakeException(Exception):
 
52
    """A fake Exception used in tests."""
 
53
 
 
54
 
50
55
class TestCaseHandler(ProcessEvent):
51
56
    """ProcessEvent used for test cases."""
52
57
 
613
618
        watch = Watch(1, path, None, True, None)
614
619
        self.assertEqual(watch.started, watch._watch_started_deferred)
615
620
 
 
621
    def random_error(self, *args):
 
622
        """Throw a fake exception."""
 
623
        raise FakeException()
 
624
 
 
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)
 
633
 
 
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",
 
639
                   self.random_error)
 
640
        watch = Watch(1, test_path, None, True, None)
 
641
        d = watch.start_watching()
 
642
        yield self.assertFailure(d, FakeException)
 
643
 
 
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")
 
648
        close_called = []
 
649
        self.patch(filesystem_notifications, "CloseHandle",
 
650
                   close_called.append)
 
651
        self.patch(filesystem_notifications, "ReadDirectoryChangesW",
 
652
                   self.random_error)
 
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)
 
657
 
616
658
 
617
659
class TestWatchManager(BaseTwistedTestCase):
618
660
    """Test the watch manager."""
627
669
        self.manager._wdm = {1: self.watch}
628
670
 
629
671
    def test_stop(self):
630
 
        """Test that the different watches are stoppe."""
 
672
        """Test that the different watches are stopped."""
631
673
        self.was_called = False
632
674
 
633
675
        def stop_watching():