/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_smart_request.py

  • Committer: Andrew Bennetts
  • Date: 2009-03-26 06:59:15 UTC
  • mto: This revision was merged to the branch mainline in revision 4207.
  • Revision ID: andrew.bennetts@canonical.com-20090326065915-n5vmwse4axfc5qhn
Fix BzrDir.open in non-main (and non-server-request) thread when bzrlib.smart.request's _pre_open_hook is installed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
import threading
20
20
 
21
21
from bzrlib import errors
 
22
from bzrlib.bzrdir import BzrDir
22
23
from bzrlib.smart import request
23
24
from bzrlib.tests import TestCase, TestCaseWithMemoryTransport
24
25
from bzrlib.transport import get_transport
203
204
        self.assertRaises(
204
205
            errors.BzrError, _pre_open_hook, get_transport('http://host/'))
205
206
 
 
207
    def test_open_bzrdir_in_non_main_thread(self):
 
208
        """Opening a bzrdir in a non-main thread should work ok.
 
209
        
 
210
        This makes sure that the globally-installed
 
211
        bzrlib.smart.request._pre_open_hook, which uses a threading.local(),
 
212
        works in a newly created thread.
 
213
        """
 
214
        bzrdir = self.make_bzrdir('.')
 
215
        transport = bzrdir.root_transport
 
216
        thread_result = []
 
217
        def t():
 
218
            BzrDir.open_from_transport(transport)
 
219
            thread_result.append('ok')
 
220
        thread = threading.Thread(target=t)
 
221
        thread.start()
 
222
        thread.join()
 
223
        self.assertEqual(['ok'], thread_result)
 
224