Fix logger shutdown behavior (#1178)

Since it is based on Thread with daemon set to True, the shutdown of logger was very likely to happen too early, what was causing some lines not to appear at the destination.

Close https://github.com/zalando/patroni/issues/1173
This commit is contained in:
Alexander Kukushkin
2019-09-17 12:27:09 +02:00
committed by GitHub
parent a88704e792
commit fa7eef3d7c
2 changed files with 2 additions and 2 deletions
-1
View File
@@ -59,7 +59,6 @@ class PatroniLogger(Thread):
def __init__(self):
super(PatroniLogger, self).__init__()
self.daemon = True
self._queue_handler = QueueHandler()
self._root_logger = logging.getLogger()
self._root_logger.addHandler(self._queue_handler)
+2 -1
View File
@@ -39,13 +39,13 @@ class MockFrozenImporter(object):
@patch.object(AsyncExecutor, 'run', Mock())
@patch.object(etcd.Client, 'write', etcd_write)
@patch.object(etcd.Client, 'read', etcd_read)
@patch.object(Thread, 'start', Mock())
class TestPatroni(unittest.TestCase):
@patch('pkgutil.get_importer', Mock(return_value=MockFrozenImporter()))
@patch('sys.frozen', Mock(return_value=True), create=True)
@patch.object(BaseHTTPServer.HTTPServer, '__init__', Mock())
@patch.object(etcd.Client, 'read', etcd_read)
@patch.object(Thread, 'start', Mock())
def setUp(self):
self._handlers = logging.getLogger().handlers[:]
RestApiServer._BaseServer__is_shut_down = Mock()
@@ -165,6 +165,7 @@ class TestPatroni(unittest.TestCase):
self.p.tags['nosync'] = None
self.assertFalse(self.p.nosync)
@patch.object(Thread, 'join', Mock())
def test_shutdown(self):
self.p.api.shutdown = Mock(side_effect=Exception)
self.p.shutdown()