mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Try to fix failing tests
Ignore errors during server __exit__ and bump ubuntu version Also retry all failing server tests once.
This commit is contained in:
parent
bf61d37d72
commit
f45278507e
4
.github/workflows/ci.yml
vendored
4
.github/workflows/ci.yml
vendored
@ -7,7 +7,7 @@ jobs:
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest, macos-latest, windows-latest]
|
||||
os: [ubuntu-20.04, macos-latest, windows-latest]
|
||||
steps:
|
||||
- name: Checkout source code
|
||||
uses: actions/checkout@master
|
||||
@ -33,7 +33,7 @@ jobs:
|
||||
|
||||
archtest:
|
||||
name: Test on Arch
|
||||
runs-on: ubuntu-latest
|
||||
runs-on: ubuntu-20.04
|
||||
container:
|
||||
image: 'archlinux/base:latest'
|
||||
env:
|
||||
|
@ -11,6 +11,7 @@ import select
|
||||
import socket
|
||||
import ssl
|
||||
import traceback
|
||||
from contextlib import suppress
|
||||
from functools import partial
|
||||
from io import BytesIO
|
||||
|
||||
@ -434,8 +435,10 @@ class ServerLoop(object):
|
||||
self.control_out = open(r, 'rb')
|
||||
|
||||
def close_control_connection(self):
|
||||
self.control_in.close()
|
||||
self.control_out.close()
|
||||
with suppress(Exception):
|
||||
self.control_in.close()
|
||||
with suppress(Exception):
|
||||
self.control_out.close()
|
||||
|
||||
def __str__(self):
|
||||
return "%s(%r)" % (self.__class__.__name__, self.bind_address)
|
||||
@ -730,12 +733,10 @@ class ServerLoop(object):
|
||||
|
||||
def shutdown(self):
|
||||
self.jobs_manager.shutdown()
|
||||
try:
|
||||
with suppress(socket.error):
|
||||
if getattr(self, 'socket', None):
|
||||
self.socket.close()
|
||||
self.socket = None
|
||||
except socket.error:
|
||||
pass
|
||||
for s, conn in tuple(iteritems(self.connection_map)):
|
||||
self.close(s, conn)
|
||||
wait_till = monotonic() + self.opts.shutdown_timeout
|
||||
|
@ -6,7 +6,7 @@ __license__ = 'GPL v3'
|
||||
__copyright__ = '2011, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||
__docformat__ = 'restructuredtext en'
|
||||
|
||||
import unittest, time, shutil, gc, tempfile, atexit, os, sys
|
||||
import unittest, time, shutil, gc, tempfile, atexit, os
|
||||
from io import BytesIO
|
||||
from functools import partial
|
||||
from threading import Thread
|
||||
@ -24,6 +24,21 @@ class BaseTest(unittest.TestCase):
|
||||
|
||||
ae = unittest.TestCase.assertEqual
|
||||
|
||||
def run(self, result=None):
|
||||
if result is None:
|
||||
result = self.defaultTestResult()
|
||||
max_retries = 1
|
||||
for i in range(max_retries + 1):
|
||||
failures_before = len(result.failures)
|
||||
errors_before = len(result.errors)
|
||||
super().run(result=result)
|
||||
if len(result.failures) == failures_before and len(result.errors) == errors_before:
|
||||
return
|
||||
print(f'Retrying test {self._testMethodName} after failure/error')
|
||||
q = result.failures if len(result.failures) > failures_before else result.errors
|
||||
q.pop(-1)
|
||||
time.sleep(1)
|
||||
|
||||
|
||||
class LibraryBaseTest(BaseTest):
|
||||
|
||||
@ -89,8 +104,6 @@ class TestServer(Thread):
|
||||
log=ServerLog(level=ServerLog.DEBUG),
|
||||
)
|
||||
self.log = self.loop.log
|
||||
# allow unittest's bufferring to work
|
||||
self.log.outputs[0].stream = sys.stdout
|
||||
|
||||
def setup_defaults(self, kwargs):
|
||||
kwargs['shutdown_timeout'] = kwargs.get('shutdown_timeout', 0.1)
|
||||
@ -112,7 +125,10 @@ class TestServer(Thread):
|
||||
return self
|
||||
|
||||
def __exit__(self, *args):
|
||||
self.loop.stop()
|
||||
try:
|
||||
self.loop.stop()
|
||||
except Exception as e:
|
||||
self.log.error('Failed to stop server with error:', e)
|
||||
self.join(self.loop.opts.shutdown_timeout)
|
||||
self.loop.close_control_connection()
|
||||
|
||||
@ -148,12 +164,14 @@ class LibraryServer(TestServer):
|
||||
plugins=plugins,
|
||||
log=ServerLog(level=ServerLog.DEBUG),
|
||||
)
|
||||
# allow unittest's bufferring to work
|
||||
self.loop.log.outputs[0].stream = sys.stdout
|
||||
self.handler.set_log(self.loop.log)
|
||||
self.log = self.loop.log
|
||||
self.handler.set_log(self.log)
|
||||
|
||||
def __exit__(self, *args):
|
||||
self.loop.stop()
|
||||
try:
|
||||
self.loop.stop()
|
||||
except Exception as e:
|
||||
self.log.error('Failed to stop server with error:', e)
|
||||
self.handler.close()
|
||||
self.join(self.loop.opts.shutdown_timeout)
|
||||
self.loop.close_control_connection()
|
||||
|
@ -79,9 +79,7 @@ class LoopTest(BaseTest):
|
||||
' Test worker semantics '
|
||||
with TestServer(lambda data:(data.path[0] + data.read()), worker_count=3) as server:
|
||||
self.ae(3, sum(int(w.is_alive()) for w in server.loop.pool.workers))
|
||||
server.loop.stop()
|
||||
server.join()
|
||||
self.ae(0, sum(int(w.is_alive()) for w in server.loop.pool.workers))
|
||||
self.ae(0, sum(int(w.is_alive()) for w in server.loop.pool.workers))
|
||||
# Test shutdown with hung worker
|
||||
block = Event()
|
||||
with TestServer(lambda data:block.wait(), worker_count=3, shutdown_timeout=0.1, timeout=0.1) as server:
|
||||
@ -96,9 +94,11 @@ class LoopTest(BaseTest):
|
||||
raise Exception('Got unexpected response: code: %s %s headers: %r data: %r' % (
|
||||
res.status, res.reason, res.getheaders(), res.read()))
|
||||
self.ae(pool.busy, 1)
|
||||
server.loop.stop()
|
||||
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))
|
||||
block.set()
|
||||
for w in pool.workers:
|
||||
w.join()
|
||||
self.ae(0, sum(int(w.is_alive()) for w in server.loop.pool.workers))
|
||||
|
||||
def test_fallback_interface(self):
|
||||
'Test falling back to default interface'
|
||||
|
@ -40,9 +40,14 @@ class Stream(object):
|
||||
prints(*args, **kwargs, file=self.stream)
|
||||
|
||||
|
||||
stdout_sentinel = object()
|
||||
|
||||
|
||||
class ANSIStream(Stream):
|
||||
|
||||
def __init__(self, stream=sys.stdout):
|
||||
def __init__(self, stream=stdout_sentinel):
|
||||
if stream is stdout_sentinel:
|
||||
stream = sys.stdout
|
||||
Stream.__init__(self, stream)
|
||||
self.color = {
|
||||
DEBUG: 'green',
|
||||
@ -79,7 +84,9 @@ class HTMLStream(Stream):
|
||||
}
|
||||
normal = '</span>'
|
||||
|
||||
def __init__(self, stream=sys.stdout):
|
||||
def __init__(self, stream=stdout_sentinel):
|
||||
if stream is stdout_sentinel:
|
||||
stream = sys.stdout
|
||||
Stream.__init__(self, stream)
|
||||
|
||||
def prints(self, level, *args, **kwargs):
|
||||
|
Loading…
x
Reference in New Issue
Block a user