~didrocks/ubuntuone-client/dont-suffer-zg-crash

« back to all changes in this revision

Viewing changes to tests/syncdaemon/test_action_queue.py

  • Committer: Bazaar Package Importer
  • Author(s): Rodney Dawes, Chris Coulson
  • Date: 2011-04-10 21:24:30 UTC
  • mfrom: (1.1.49 upstream)
  • Revision ID: james.westby@ubuntu.com-20110410212430-u9txrycw32fbt0x2
Tags: 1.6.0-0ubuntu1
* New upstream release.
  - Avoid conflict when same file already exists locally (LP: #711389)
  - Must move fils to trash on deletion (LP: #690673)
  - Support disconnection during initial connect attempt (LP: #711211)
  - Log version number on startup (LP: #715455)
  - Memory usage too high (LP: #721483)
  - Unsubscribed folders show as synced, if they exist (LP: #741835)
  - gnome-settings-daemon crash in g_str_hash (LP: #744383)
  - Should not re-queue uploads directly (LP: #744608)
  - No feedback when creating folder from symlink fails (LP: #747299)
  - [FFE] Use API to set urgency from background process (LP: #747677)
  - Open control panel to volumes when quota exceeded (LP: #702176)
  - Set the launcher to urgent when quota exceeded (LP: #702183)
  - nautilus crash in g_str_hash (LP: #724882)
  - Disable/enable file sync is buggy (LP: #744980)

[Chris Coulson]
* gnome-settings-daemon crash in g_return_fail_if_warning (LP: #744980)

Show diffs side-by-side

added added

removed removed

Lines of Context:
56
56
    request,
57
57
)
58
58
from ubuntuone.syncdaemon import states, interfaces
 
59
from ubuntuone.syncdaemon import action_queue
59
60
from ubuntuone.syncdaemon.action_queue import (
60
61
    ActionQueue, ActionQueueCommand, ChangePublicAccess, CreateUDF,
61
 
    DeleteVolume, Download, ListVolumes, ActionQueueProtocol,
 
62
    DeleteVolume, Download, ListVolumes, ActionQueueProtocol, ListShares,
62
63
    RequestQueue, UploadProgressWrapper, Upload, SIMULT_TRANSFERS,
63
64
    CreateShare, DeleteShare, GetPublicFiles, GetDelta, GetDeltaFromScratch,
64
65
    TRANSFER_PROGRESS_THRESHOLD, Unlink, Move, MakeFile, MakeDir, DeltaList,
1236
1237
 
1237
1238
        yield self._disconnect_factory()
1238
1239
 
 
1240
    def test_connection_started_logging(self):
 
1241
        """Test that the connection started logs connector info, not AQ's."""
 
1242
        assert self.action_queue.host == '127.0.0.1'
 
1243
        assert self.action_queue.port == 0
 
1244
 
 
1245
        class FakeConnector(object):
 
1246
            """Fake connector."""
 
1247
            host = '1.2.3.4'
 
1248
            port = 4321
 
1249
 
 
1250
        self.action_queue.startedConnecting(FakeConnector())
 
1251
        self.assertTrue(self.handler.check_info("Connection started",
 
1252
                                                "host 1.2.3.4", "port 4321"))
 
1253
 
1239
1254
 
1240
1255
class NetworkmanagerTestCase(FactoryBaseTestCase):
1241
1256
    """Base test case generating a connected factory."""
1719
1734
    def test_go_run_bad_release_pathlock(self):
1720
1735
        """If run went bad, release the pathlock."""
1721
1736
        called = []
1722
 
        self.cmd.run = lambda: defer.fail(ValueError())
 
1737
        self.cmd.run = lambda: defer.fail(ValueError("error message"))
1723
1738
        self.cmd._acquire_pathlock = lambda: defer.succeed(
1724
1739
                                                lambda: called.append(True))
1725
1740
 
1726
 
        try:
1727
 
            yield self.cmd.go()
1728
 
        except ValueError:
1729
 
            pass # consume!
1730
 
        else:
1731
 
            self.fail("It didn't raise an exception!")
 
1741
        yield self.cmd.go()
1732
1742
        self.assertTrue(called)
1733
1743
 
 
1744
        # check exception to assure a traceback was logged, and check the
 
1745
        # messages in ERROR (the real logging level); finally, clean the
 
1746
        # records as if we leave them with the exception the test will fail
 
1747
        self.assertTrue(self.handler.check_exception(ValueError))
 
1748
        self.assertTrue(self.handler.check_error("Error running the command",
 
1749
                                                 "error message"))
 
1750
        self.handler.records = []
 
1751
 
1734
1752
    def test_run_initial(self):
1735
1753
        """Call ._start, log, and set running."""
1736
1754
        called = []
1737
 
        self.cmd._start = lambda: called.append(True)# or defer.succeed(True)
 
1755
        d = defer.Deferred()
 
1756
        self.cmd._start = lambda: called.append(True) or d
1738
1757
 
 
1758
        # run, and will lock in the _start
1739
1759
        self.cmd.run()
1740
 
        self.assertFalse(self.cmd.running)
1741
1760
        self.assertTrue(called)
1742
1761
        self.assertTrue(self.handler.check_debug('starting'))
1743
1762
 
 
1763
        # release the _start, check log and that it still not running
 
1764
        d.callback(True)
 
1765
        self.assertTrue(self.handler.check_debug('started'))
 
1766
        self.assertFalse(self.cmd.running)
 
1767
 
1744
1768
    def test_run_stop_if_cancelled_while_start(self):
1745
1769
        """Cancelled while _start."""
1746
1770
        self.rq.queue(self.cmd)
2072
2096
        self.assertFalse(called)
2073
2097
        self.assertTrue(self.cmd.cancelled)
2074
2098
 
 
2099
    def test_slots(self):
 
2100
        """Inherited commands must have __slot__ (that is not inherited)."""
 
2101
        for obj_name in dir(action_queue):
 
2102
            obj = getattr(action_queue, obj_name)
 
2103
            if isinstance(obj, type) and issubclass(obj, ActionQueueCommand) \
 
2104
               and obj is not ActionQueueCommand:
 
2105
                self.assertNotIdentical(obj.__slots__,
 
2106
                                        ActionQueueCommand.__slots__,
 
2107
                                        "class %s has no __slots__" % obj)
 
2108
 
2075
2109
 
2076
2110
class CreateUDFTestCase(ConnectedBaseTestCase):
2077
2111
    """Test for CreateUDF ActionQueueCommand."""
2269
2303
        return self.deferred
2270
2304
 
2271
2305
 
 
2306
class ListSharesTestCase(ConnectedBaseTestCase):
 
2307
    """Test for ListShares ActionQueueCommand."""
 
2308
 
 
2309
    def setUp(self):
 
2310
        """Set up."""
 
2311
        res = super(ListSharesTestCase, self).setUp()
 
2312
        self.rq = RequestQueue(action_queue=self.action_queue)
 
2313
        return res
 
2314
 
 
2315
    def test_queued_mixed_types(self):
 
2316
        """Command gets queued if other command is waiting."""
 
2317
        cmd1 = FakeCommand()
 
2318
        self.rq.queue(cmd1)
 
2319
        cmd2 = ListShares(self.rq)
 
2320
        self.assertTrue(cmd2._should_be_queued())
 
2321
 
 
2322
    def test_queued_two(self):
 
2323
        """Two queued commands is not ok."""
 
2324
        cmd1 = ListShares(self.rq)
 
2325
        self.rq.queue(cmd1)
 
2326
        cmd2 = ListShares(self.rq)
 
2327
        self.assertFalse(cmd2._should_be_queued())
 
2328
 
 
2329
    def test_uniqueness(self):
 
2330
        """Info used for uniqueness."""
 
2331
        cmd = ListShares(self.rq)
 
2332
        self.assertEqual(cmd.uniqueness, 'ListShares')
 
2333
 
 
2334
 
2272
2335
class ListVolumesTestCase(ConnectedBaseTestCase):
2273
2336
    """Test for ListVolumes ActionQueueCommand."""
2274
2337
 
2276
2339
        """Init."""
2277
2340
        res = super(ListVolumesTestCase, self).setUp()
2278
2341
 
2279
 
        request_queue = RequestQueue(action_queue=self.action_queue)
2280
 
        self.command = ListVolumes(request_queue)
 
2342
        self.rq = RequestQueue(action_queue=self.action_queue)
 
2343
        self.command = ListVolumes(self.rq)
2281
2344
 
2282
2345
        return res
2283
2346
 
2324
2387
        event = ('AQ_LIST_VOLUMES_ERROR', {'error': msg})
2325
2388
        self.assertIn(event, self.command.action_queue.event_queue.events)
2326
2389
 
 
2390
    def test_queued_mixed_types(self):
 
2391
        """Command gets queued if other command is waiting."""
 
2392
        cmd1 = FakeCommand()
 
2393
        self.rq.queue(cmd1)
 
2394
        cmd2 = ListVolumes(self.rq)
 
2395
        self.assertTrue(cmd2._should_be_queued())
 
2396
 
 
2397
    def test_queued_two(self):
 
2398
        """Two queued commands is not ok."""
 
2399
        cmd1 = ListVolumes(self.rq)
 
2400
        self.rq.queue(cmd1)
 
2401
        cmd2 = ListVolumes(self.rq)
 
2402
        self.assertFalse(cmd2._should_be_queued())
 
2403
 
 
2404
    def test_uniqueness(self):
 
2405
        """Info used for uniqueness."""
 
2406
        cmd = ListVolumes(self.rq)
 
2407
        self.assertEqual(cmd.uniqueness, 'ListVolumes')
 
2408
 
2327
2409
 
2328
2410
class DeleteVolumeTestCase(ConnectedBaseTestCase):
2329
2411
    """Test for DeleteVolume ActionQueueCommand."""
2516
2598
    def setUp(self):
2517
2599
        super(GetPublicFilesTestCase, self).setUp()
2518
2600
        self.user_connect()
2519
 
        request_queue = RequestQueue(action_queue=self.action_queue)
2520
 
        self.command = GetPublicFiles(request_queue)
 
2601
        self.rq = RequestQueue(action_queue=self.action_queue)
 
2602
        self.command = GetPublicFiles(self.rq)
2521
2603
 
2522
2604
    def test_init(self):
2523
2605
        """Test __init__ method."""
2606
2688
        event = ('AQ_PUBLIC_FILES_LIST_ERROR', {'error': msg})
2607
2689
        self.assertIn(event, self.command.action_queue.event_queue.events)
2608
2690
 
 
2691
    def test_queued_mixed_types(self):
 
2692
        """Command gets queued if other command is waiting."""
 
2693
        cmd1 = FakeCommand()
 
2694
        self.rq.queue(cmd1)
 
2695
        cmd2 = GetPublicFiles(self.rq)
 
2696
        self.assertTrue(cmd2._should_be_queued())
 
2697
 
 
2698
    def test_queued_two(self):
 
2699
        """Two queued commands is not ok."""
 
2700
        cmd1 = GetPublicFiles(self.rq)
 
2701
        self.rq.queue(cmd1)
 
2702
        cmd2 = GetPublicFiles(self.rq)
 
2703
        self.assertFalse(cmd2._should_be_queued())
 
2704
 
 
2705
    def test_uniqueness(self):
 
2706
        """Info used for uniqueness."""
 
2707
        cmd = GetPublicFiles(self.rq)
 
2708
        self.assertEqual(cmd.uniqueness, 'GetPublicFiles')
 
2709
 
2609
2710
 
2610
2711
class DownloadUnconnectedTestCase(FactoryBaseTestCase):
2611
2712
    """Test for Download ActionQueueCommand, no connection"""
3836
3937
                                                event, str(exc)))
3837
3938
 
3838
3939
    @defer.inlineCallbacks
 
3940
    def assert_send_request_and_handle_errors_on_connection_end(self, exc):
 
3941
        """_send_request_and_handle_errors is ok when connection lost/done."""
 
3942
        request = self.fail_please(exc)
 
3943
        kwargs = dict(request=request, request_error=SpecificException,
 
3944
                      event_error='BAR', event_ok='FOO')
 
3945
        d = self.action_queue._send_request_and_handle_errors(**kwargs)
 
3946
        yield d
 
3947
 
 
3948
        # check that SYS_UNKNOWN_ERROR wasn't sent, and that logged ok
 
3949
        events = self.action_queue.event_queue.events
 
3950
        self.assertNotIn('SYS_UNKNOWN_ERROR', [x[0] for x in events])
 
3951
        self.assertTrue(self.handler.check_info(request.__name__, str(exc)))
 
3952
 
 
3953
    def test_send_request_and_handle_errors_on_connection_lost(self):
 
3954
        """_send_request_and_handle_errors is correct when connection lost."""
 
3955
        e = twisted_error.ConnectionLost()
 
3956
        return self.assert_send_request_and_handle_errors_on_connection_end(e)
 
3957
 
 
3958
    def test_send_request_and_handle_errors_on_connection_done(self):
 
3959
        """_send_request_and_handle_errors is correct when connection lost."""
 
3960
        e = twisted_error.ConnectionDone()
 
3961
        return self.assert_send_request_and_handle_errors_on_connection_end(e)
 
3962
 
 
3963
    @defer.inlineCallbacks
3839
3964
    def assert_send_request_and_handle_errors_on_server_error(self, serr):
3840
3965
        """_send_request_and_handle_errors is correct when server error."""
3841
3966
        # XXX: we need to replace this list with and exception list