~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_serve.py

  • Committer: John Arbash Meinel
  • Date: 2011-09-26 12:30:01 UTC
  • mto: This revision was merged to the branch mainline in revision 6170.
  • Revision ID: john@arbash-meinel.com-20110926123001-96eg7yfnizx3sd1c
Fix the blackbox test to wait for the process to exit.
Update the test so that we both check it doesn't shut down until the request
is done, and so that we check that it does shut down afterwards.

Show diffs side-by-side

added added

removed removed

Lines of Context:
315
315
        self.assertServerFinishesCleanly(process)
316
316
 
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
 
331
        # request to finish
 
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
 
340
        # been disconnected.
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())
331
344
 
332
345
 
333
346
class TestCmdServeChrooting(TestBzrServeBase):