diff --git a/tests/test_log.py b/tests/test_log.py
index 11e8178bc..5f9e795ca 100644
--- a/tests/test_log.py
+++ b/tests/test_log.py
@@ -79,9 +79,11 @@ def test_patroni_logger(self):
                               Mock(side_effect=[logging.LogRecord('', logging.INFO, '', 0, '', (), None), Exception])):
                 logging.exception('test')
             logging.error('test')
+            # Stop the logger thread before mocking put_nowait(), otherwise its asynchronous
+            # "Failed to close the old log handler" record could be lost and counted in records_lost.
+            self.assertRaises(Exception, logger.shutdown)
             with patch.object(Queue, 'put_nowait', Mock(side_effect=Full)):
                 self.assertRaises(SystemExit, logger.shutdown)
-            self.assertRaises(Exception, logger.shutdown)
         self.assertLessEqual(logger.queue_size, 2)  # "Failed to close the old log handler" could be still in the queue
         self.assertEqual(logger.records_lost, 0)
         del config['log']['traceback_level']
