1
# Copyright (C) 2010 Canonical Ltd
1
# Copyright (C) 2010, 2011 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
26
26
from bzrlib.tests import test_server
29
def load_tests(basic_tests, module, loader):
30
suite = loader.suiteClass()
31
server_tests, remaining_tests = tests.split_suite_by_condition(
32
basic_tests, tests.condition_isinstance(TestTCPServerInAThread))
33
server_scenarios = [ (name, {'server_class': getattr(test_server, name)})
35
('TestingTCPServer', 'TestingThreadingTCPServer')]
36
tests.multiply_tests(server_tests, server_scenarios, suite)
37
suite.addTest(remaining_tests)
41
class TestThreadWithException(tests.TestCase):
43
def test_start_and_join_smoke_test(self):
47
tt = test_server.ThreadWithException(target=do_nothing)
51
def test_exception_is_re_raised(self):
52
class MyException(Exception):
55
def raise_my_exception():
58
tt = test_server.ThreadWithException(target=raise_my_exception)
60
self.assertRaises(MyException, tt.join)
62
def test_join_when_no_exception(self):
63
resume = threading.Event()
64
class MyException(Exception):
67
def raise_my_exception():
68
# Wait for the test to tell us to resume
73
tt = test_server.ThreadWithException(target=raise_my_exception)
76
self.assertIs(None, tt.exception)
78
self.assertRaises(MyException, tt.join)
27
from bzrlib.tests.scenarios import load_tests_apply_scenarios
30
load_tests = load_tests_apply_scenarios
81
33
class TCPClient(object):
130
82
class TestTCPServerInAThread(tests.TestCase):
85
(name, {'server_class': getattr(test_server, name)})
87
('TestingTCPServer', 'TestingThreadingTCPServer')]
132
89
# Set by load_tests()
133
90
server_class = None
225
182
def handle_connection(self):
226
183
req = self.rfile.readline()
227
threading.currentThread().set_ready_event(sync)
184
threading.currentThread().set_sync_event(sync)
228
185
raise FailToRespond()
230
187
server = self.get_server(