~mikemc/ubuntuone-control-panel/remote-folders-fix

« back to all changes in this revision

Viewing changes to ubuntuone/controlpanel/tests/test_backend.py

  • Committer: Tarmac
  • Author(s): mike.mccracken at canonical
  • Date: 2012-08-30 02:12:00 UTC
  • mfrom: (352.1.3 trunk)
  • Revision ID: tarmac-20120830021200-aap1n5kp61xqjeg4
- Fix race in backend get_credentials call. (LP: #1042860)

Show diffs side-by-side

added added

removed removed

Lines of Context:
524
524
        self.assertEqual(self.be.login_client._called['find_credentials'], 1)
525
525
 
526
526
    @inlineCallbacks
 
527
    def test_credentials_are_cached_slow(self):
 
528
        """The credentials are still cached when find_credentials is slow."""
 
529
        dq = defer.DeferredQueue()
 
530
 
 
531
        @inlineCallbacks
 
532
        def delayed_find_creds():
 
533
            """Function with externally controlled return time."""
 
534
            fake_creds = yield dq.get()
 
535
            defer.returnValue(fake_creds)
 
536
 
 
537
        self.patch(self.be.login_client, 'find_credentials',
 
538
                   delayed_find_creds)
 
539
 
 
540
        # Ensure that the second call to get_credentials occurs before
 
541
        # the first one gets a result from find_credentials by leaving
 
542
        # the queue empty until both are called:
 
543
 
 
544
        d1 = self.be.get_credentials()
 
545
        d2 = self.be.get_credentials()
 
546
        dq.put("Blizzard")
 
547
        dq.put("Dilly Bar")
 
548
        creds1 = yield d1
 
549
        creds2 = yield d2
 
550
        self.assertEqual(creds1, creds2)
 
551
 
 
552
    @inlineCallbacks
527
553
    def test_clear_credentials(self):
528
554
        """The credentials can be cleared."""
529
555
        # ensure we have creds