Remove unneeded code

Thanks to bufferring we dont need to mess with log filtering levels
anymore
This commit is contained in:
Kovid Goyal 2020-12-08 14:19:43 +05:30
parent 4a8baa5fec
commit 92007117bc
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 3 additions and 15 deletions

View File

@ -76,7 +76,7 @@ class TestServer(Thread):
daemon = True daemon = True
def __init__(self, handler, plugins=(), specialize=lambda srv:None, **kwargs): def __init__(self, handler, plugins=(), **kwargs):
Thread.__init__(self, name='ServerMain') Thread.__init__(self, name='ServerMain')
from calibre.srv.opts import Options from calibre.srv.opts import Options
from calibre.srv.loop import ServerLoop from calibre.srv.loop import ServerLoop
@ -91,7 +91,6 @@ class TestServer(Thread):
self.log = self.loop.log self.log = self.loop.log
# allow unittest's bufferring to work # allow unittest's bufferring to work
self.log.outputs[0].stream = sys.stdout self.log.outputs[0].stream = sys.stdout
specialize(self)
def setup_defaults(self, kwargs): def setup_defaults(self, kwargs):
kwargs['shutdown_timeout'] = kwargs.get('shutdown_timeout', 0.1) kwargs['shutdown_timeout'] = kwargs.get('shutdown_timeout', 0.1)
@ -133,7 +132,7 @@ class TestServer(Thread):
class LibraryServer(TestServer): class LibraryServer(TestServer):
def __init__(self, library_path, libraries=(), plugins=(), specialize=lambda x:None, **kwargs): def __init__(self, library_path, libraries=(), plugins=(), **kwargs):
Thread.__init__(self, name='ServerMain') Thread.__init__(self, name='ServerMain')
from calibre.srv.opts import Options from calibre.srv.opts import Options
from calibre.srv.loop import ServerLoop from calibre.srv.loop import ServerLoop
@ -152,7 +151,6 @@ class LibraryServer(TestServer):
# allow unittest's bufferring to work # allow unittest's bufferring to work
self.loop.log.outputs[0].stream = sys.stdout self.loop.log.outputs[0].stream = sys.stdout
self.handler.set_log(self.loop.log) self.handler.set_log(self.loop.log)
specialize(self)
def __exit__(self, *args): def __exit__(self, *args):
self.loop.stop() self.loop.stop()

View File

@ -196,14 +196,11 @@ class TestHTTP(BaseTest):
self.ae(r.read(), b'Requested resource not found') self.ae(r.read(), b'Requested resource not found')
# Test 500 # Test 500
orig = server.loop.log.filter_level
server.loop.log.filter_level = server.loop.log.ERROR + 10
server.change_handler(lambda data:1/0) server.change_handler(lambda data:1/0)
conn = server.connect() conn = server.connect()
conn.request('GET', '/test/') conn.request('GET', '/test/')
r = conn.getresponse() r = conn.getresponse()
self.ae(r.status, http_client.INTERNAL_SERVER_ERROR) self.ae(r.status, http_client.INTERNAL_SERVER_ERROR)
server.loop.log.filter_level = orig
# Test 301 # Test 301
def handler(data): def handler(data):
@ -244,9 +241,6 @@ class TestHTTP(BaseTest):
self.ae(r.status, http_client.OK) self.ae(r.status, http_client.OK)
self.ae(r.read(), b'testbody1234567890') self.ae(r.read(), b'testbody1234567890')
# Test various incorrect input
orig_level, server.log.filter_level = server.log.filter_level, server.log.ERROR
conn.request('GET', '/test' + ('a' * 200)) conn.request('GET', '/test' + ('a' * 200))
r = conn.getresponse() r = conn.getresponse()
self.ae(r.status, http_client.BAD_REQUEST) self.ae(r.status, http_client.BAD_REQUEST)
@ -284,7 +278,6 @@ class TestHTTP(BaseTest):
self.ae(r.status, http_client.REQUEST_TIMEOUT) self.ae(r.status, http_client.REQUEST_TIMEOUT)
self.assertIn(b'', r.read()) self.assertIn(b'', r.read())
server.log.filter_level = orig_level
conn = server.connect() conn = server.connect()
# Test closing # Test closing

View File

@ -96,16 +96,13 @@ class LoopTest(BaseTest):
raise Exception('Got unexpected response: code: %s %s headers: %r data: %r' % ( raise Exception('Got unexpected response: code: %s %s headers: %r data: %r' % (
res.status, res.reason, res.getheaders(), res.read())) res.status, res.reason, res.getheaders(), res.read()))
self.ae(pool.busy, 1) self.ae(pool.busy, 1)
server.loop.log.filter_level = server.loop.log.ERROR
server.loop.stop() server.loop.stop()
server.join() server.join()
self.ae(1, sum(int(w.is_alive()) for w in pool.workers)) self.ae(1, sum(int(w.is_alive()) for w in pool.workers))
def test_fallback_interface(self): def test_fallback_interface(self):
'Test falling back to default interface' 'Test falling back to default interface'
def specialize(server): with TestServer(lambda data:(data.path[0] + data.read()), listen_on='1.1.1.1', fallback_to_detected_interface=True) as server:
server.loop.log.filter_level = server.loop.log.ERROR
with TestServer(lambda data:(data.path[0] + data.read()), listen_on='1.1.1.1', fallback_to_detected_interface=True, specialize=specialize) as server:
self.assertNotEqual('1.1.1.1', server.address[0]) self.assertNotEqual('1.1.1.1', server.address[0])
@skipIf(True, 'Disabled as it is failing on the build server, need to investigate') @skipIf(True, 'Disabled as it is failing on the build server, need to investigate')