58
57
Returns stdout and stderr.
60
def on_server_start(backing_urls, tcp_server):
62
target=on_server_start_thread, args=(tcp_server,))
60
64
def on_server_start_thread(tcp_server):
61
"""This runs concurrently with the server thread.
63
The server is interrupted as soon as ``func`` finishes, even if an
64
exception is encountered.
68
67
self.tcp_server = tcp_server
72
71
except Exception, e:
73
72
# Log errors to make some test failures a little less
75
trace.mutter('func broke: %r', e)
74
mutter('func broke: %r', e)
77
76
# Then stop the server
78
trace.mutter('interrupting...')
77
mutter('interrupting...')
79
78
thread.interrupt_main()
80
# When the hook is fired, it just starts ``on_server_start_thread`` and
82
def on_server_start(backing_urls, tcp_server):
84
target=on_server_start_thread, args=(tcp_server,))
87
79
SmartTCPServer.hooks.install_named_hook(
88
80
'server_started_ex', on_server_start,
89
81
'run_bzr_serve_then_func hook')
90
82
# start a TCP server
92
out, err = self.run_bzr(['serve'] + list(serve_args),
84
out, err = self.run_bzr(['serve'] + list(serve_args))
94
85
except KeyboardInterrupt, e:
102
93
super(TestBzrServe, self).setUp()
103
94
self.disable_missing_extensions_warning()
105
def test_server_exception_with_hook(self):
106
"""Catch exception from the server in the server_exception hook.
108
We use ``run_bzr_serve_then_func`` without a ``func`` so the server
109
will receive a KeyboardInterrupt exception we want to catch.
112
if exception[0] is KeyboardInterrupt:
113
sys.stderr.write('catching KeyboardInterrupt\n')
117
SmartTCPServer.hooks.install_named_hook(
118
'server_exception', hook,
119
'test_server_except_hook hook')
120
args = ['--port', 'localhost:0', '--quiet']
121
out, err = self.run_bzr_serve_then_func(args, retcode=0)
122
self.assertEqual('catching KeyboardInterrupt\n', err)
124
def test_server_exception_no_hook(self):
125
"""test exception without hook returns error"""
127
out, err = self.run_bzr_serve_then_func(args, retcode=3)
129
96
def assertInetServerShutsdownCleanly(self, process):
130
97
"""Shutdown the server process looking for errors."""
131
98
# Shutdown the server: the server should shut down when it cannot read
308
275
class TestUserdirExpansion(TestCaseWithMemoryTransport):
311
def fake_expanduser(path):
277
def fake_expanduser(self, path):
312
278
"""A simple, environment-independent, function for the duration of this