~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_http.py

Add an event to ThreadWithException that can be shared with the calling thread.

* bzrlib/tests/test_server.py:
(ThreadWithException.__init__): Add an 'event' parameter that can
be shared with the caller.
(ThreadWithException.run): Sset the event once the exception has
been recorded so we can release the caller and provide the
exception.
(ThreadWithException.join): Properly raise the recorded exception.

* bzrlib/tests/test_http.py:
(TestHTTPServer.test_force_invalid_protocol): Just rely on
assertRaises or we don't get the traceback on error.
(TestHTTPServer.test_server_start_and_stop): Cleanup.

* bzrlib/tests/http_server.py:
(HttpServer._http_start): Simplified.
(HttpServer.start_server): Leave the ThreadWithException do its
work.
(HttpServer.stop_server): Shutdown the server only if it was
started.

Show diffs side-by-side

added added

removed removed

Lines of Context:
340
340
 
341
341
    def test_force_invalid_protocol(self):
342
342
        server = http_server.HttpServer(protocol_version='HTTP/0.1')
343
 
        try:
344
 
            self.assertRaises(httplib.UnknownProtocol, server.start_server)
345
 
        except:
346
 
            server.stop_server()
347
 
            self.fail('HTTP Server creation did not raise UnknownProtocol')
 
343
        self.addCleanup(server.stop_server)
 
344
        self.assertRaises(httplib.UnknownProtocol, server.start_server)
348
345
 
349
346
    def test_server_start_and_stop(self):
350
347
        server = http_server.HttpServer()
 
348
        self.addCleanup(server.stop_server)
351
349
        server.start_server()
352
 
        try:
353
 
            self.assertTrue(server._httpd is not None)
354
 
            self.assertTrue(server._httpd.serving is not None)
355
 
            self.assertTrue(server._httpd.serving.isSet())
356
 
        finally:
357
 
            server.stop_server()
 
350
        self.assertTrue(server._httpd is not None)
 
351
        self.assertTrue(server._httpd.serving is not None)
 
352
        self.assertTrue(server._httpd.serving.isSet())
358
353
 
359
354
    def test_create_http_server_one_zero(self):
360
355
        class RequestHandlerOneZero(http_server.TestingHTTPRequestHandler):