From Dan Kenigsberg <danken(a)redhat.com>:
Dan Kenigsberg has uploaded a new change for review.
Change subject: [WIP] tests: CountFilesPlugin
......................................................................
[WIP] tests: CountFilesPlugin
A proper test should clean after itself, and close all the files it had
opened. Enabling this plugin, with --with-countfiles, shows which test
(or its tested code), fail to do so.
Change-Id: Ic71224f3c24b04cf4d08889338722cf248bcb2a9
Signed-off-by: Dan Kenigsberg <danken(a)redhat.com>
---
M tests/testValidation.py
M tests/testlib.py
2 files changed, 32 insertions(+), 1 deletion(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/42/69042/1
diff --git a/tests/testValidation.py b/tests/testValidation.py
index a4b6789..ed84c19 100644
--- a/tests/testValidation.py
+++ b/tests/testValidation.py
@@ -107,6 +107,36 @@
raise Exception('thread leak: %s ' % diff)
+class CountFilesPlugin(Plugin):
+ """
+ Check whether a test (or the code it triggers) open files and do not close
+ them.
+ """
+ name = 'countfiles'
+
+ def _readlink_if_exists(self, path):
+ try:
+ return os.readlink(path)
+ except OSError as e:
+ if e.errno != errno.ENOENT:
+ raise
+
+ def _open_files(self):
+ fddir = '/proc/%s/fd/' % os.getpid()
+
+ return frozenset(
+ self._readlink_if_exists(fddir + path) for path
+ in os.listdir(fddir))
+
+ def startTest(self, test):
+ self._start_files = self._open_files()
+
+ def stopTest(self, test):
+ diff = self._open_files() - self._start_files
+ if diff:
+ raise Exception('file leak: %s ' % diff)
+
+
def ValidateRunningAsRoot(f):
@wraps(f)
def wrapper(*args, **kwargs):
diff --git a/tests/testlib.py b/tests/testlib.py
index 8a55e6e..694457d 100644
--- a/tests/testlib.py
+++ b/tests/testlib.py
@@ -59,7 +59,7 @@
from monkeypatch import Patch
from testValidation import (
- SlowTestsPlugin, StressTestsPlugin, CountThreadsPlugin)
+ SlowTestsPlugin, StressTestsPlugin, CountThreadsPlugin, CountFilesPlugin)
# /tmp may use tempfs filesystem, not suitable for some of the test assuming a
# filesystem with direct io support.
@@ -435,6 +435,7 @@
conf.plugins.addPlugin(SlowTestsPlugin())
conf.plugins.addPlugin(StressTestsPlugin())
conf.plugins.addPlugin(CountThreadsPlugin())
+ conf.plugins.addPlugin(CountFilesPlugin())
runner = VdsmTestRunner(stream=conf.stream,
verbosity=conf.verbosity,
--
To view, visit
https://gerrit.ovirt.org/69042
To unsubscribe, visit
https://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic71224f3c24b04cf4d08889338722cf248bcb2a9
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Dan Kenigsberg <danken(a)redhat.com>