315
315
self.assertServerFinishesCleanly(process)
317
317
def test_bzr_serve_graceful_shutdown(self):
318
self.build_tree_contents([('a_file', 'contents\n')])
318
big_contents = 'a'*64*1024
319
self.build_tree_contents([('bigfile', big_contents)])
319
320
process, url = self.start_server_port(['--client-timeout=1.0'])
320
# TODO: I would like to test this by having a large data set that we
321
# want to finish reading before exiting. So the server should be
322
# blocked but not accepting new connections after SIGHUP.
323
321
t = transport.get_transport_from_url(url)
324
self.assertEqual('contents\n', t.get_bytes('a_file'))
322
m = t.get_smart_medium()
323
c = client._SmartClient(m)
324
# Start, but don't finish a response
325
resp, response_handler = c.call_expecting_body('get', 'bigfile')
326
self.assertEqual(('ok',), resp)
325
327
# Note: process.send_signal is a Python 2.6ism
326
328
process.send_signal(signal.SIGHUP)
327
m = t.get_smart_medium()
329
# Wait for the server to notice the signal, and then read the actual
330
# body of the response. That way we know that it is waiting for the
332
self.assertEqual('Requested to stop gracefully\n',
333
process.stderr.readline())
334
self.assertEqual('Waiting for 1 client(s) to finish\n',
335
process.stderr.readline())
336
body = response_handler.read_body_bytes()
337
if body != big_contents:
338
self.fail('Failed to properly read the contents of "bigfile"')
339
# Now that our request is finished, the medium should notice it has
328
341
self.assertEqual('', m.read_bytes(1))
329
err = process.stderr.readline()
330
self.assertEqual('Requested to stop gracefully\n', err)
342
# And the server should be stopping
343
self.assertEqual(0, process.wait())
333
346
class TestCmdServeChrooting(TestBzrServeBase):