~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_test_server.py

Merge pt1 hooks branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
load_tests = load_tests_apply_scenarios
31
31
 
32
32
 
33
 
class TestThreadWithException(tests.TestCase):
34
 
 
35
 
    def test_start_and_join_smoke_test(self):
36
 
        def do_nothing():
37
 
            pass
38
 
 
39
 
        tt = test_server.ThreadWithException(target=do_nothing)
40
 
        tt.start()
41
 
        tt.join()
42
 
 
43
 
    def test_exception_is_re_raised(self):
44
 
        class MyException(Exception):
45
 
            pass
46
 
 
47
 
        def raise_my_exception():
48
 
            raise MyException()
49
 
 
50
 
        tt = test_server.ThreadWithException(target=raise_my_exception)
51
 
        tt.start()
52
 
        self.assertRaises(MyException, tt.join)
53
 
 
54
 
    def test_join_when_no_exception(self):
55
 
        resume = threading.Event()
56
 
        class MyException(Exception):
57
 
            pass
58
 
 
59
 
        def raise_my_exception():
60
 
            # Wait for the test to tell us to resume
61
 
            resume.wait()
62
 
            # Now we can raise
63
 
            raise MyException()
64
 
 
65
 
        tt = test_server.ThreadWithException(target=raise_my_exception)
66
 
        tt.start()
67
 
        tt.join(timeout=0)
68
 
        self.assertIs(None, tt.exception)
69
 
        resume.set()
70
 
        self.assertRaises(MyException, tt.join)
71
 
 
72
 
 
73
33
class TCPClient(object):
74
34
 
75
35
    def __init__(self):
221
181
 
222
182
            def handle_connection(self):
223
183
                req = self.rfile.readline()
224
 
                threading.currentThread().set_ready_event(sync)
 
184
                threading.currentThread().set_sync_event(sync)
225
185
                raise FailToRespond()
226
186
 
227
187
        server = self.get_server(
243
203
            def handle(self):
244
204
                # We want to sync with the thread that is serving the
245
205
                # connection.
246
 
                threading.currentThread().set_ready_event(sync)
 
206
                threading.currentThread().set_sync_event(sync)
247
207
                raise CantServe()
248
208
 
249
209
        server = self.get_server(