~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_transport.py

join(timeout=0) is useful to check for an exception without stopping the thread.

* bzrlib/tests/test_server.py:
(ThreadWithException.join): Document the timeout=0 idiom.

* bzrlib/tests/test_transport.py:
(TestThreadWithException.test_exception_is_re_raised): Ensure
join(timeout=0) can be called while leaving the thread running

Show diffs side-by-side

added added

removed removed

Lines of Context:
1011
1011
        tt = test_server.ThreadWithException(target=raise_my_exception)
1012
1012
        tt.start()
1013
1013
        self.assertRaises(MyException, tt.join)
 
1014
 
 
1015
    def test_join_when_no_exception(self):
 
1016
        resume = threading.Event()
 
1017
        class MyException(Exception):
 
1018
            pass
 
1019
 
 
1020
        def raise_my_exception():
 
1021
            # Wait for the test to tell us to resume
 
1022
            resume.wait()
 
1023
            # Now we can raise
 
1024
            raise MyException()
 
1025
 
 
1026
        tt = test_server.ThreadWithException(target=raise_my_exception)
 
1027
        tt.start()
 
1028
        tt.join(timeout=0)
 
1029
        self.assertIs(None, tt.exception)
 
1030
        resume.set()
 
1031
        self.assertRaises(MyException, tt.join)