Cleanup logging handlers
We were leaking logging handlers which resulted in slowing down test
runners as they ran. This got worse as more tests ran in a single
process so individual tests run slower with less contention in the test
suite.
Fix this by cleaning up the handlers at the end of each job. Local
testing shows that this doesn't fix all the full test suite slowness but
reduced slowest test runtime by a third.
Change-Id: Iaa4b44cd98f7c874a978aef5fcb290fccf105650
diff --git a/tests/base.py b/tests/base.py
index 5f6022a..9983103 100755
--- a/tests/base.py
+++ b/tests/base.py
@@ -1220,6 +1220,12 @@
logger.setLevel(logging.DEBUG)
logger.addHandler(handler)
+ # Make sure we don't carry old handlers around in process state
+ # which slows down test runs
+ self.addCleanup(logger.removeHandler, handler)
+ self.addCleanup(handler.close)
+ self.addCleanup(handler.flush)
+
# NOTE(notmorgan): Extract logging overrides for specific
# libraries from the OS_LOG_DEFAULTS env and create loggers
# for each. This is used to limit the output during test runs