From Dan Kenigsberg <danken(a)redhat.com>:
Dan Kenigsberg has uploaded a new change for review.
Change subject: tests: CountThreadsPlugin
......................................................................
tests: CountThreadsPlugin
Enable this test plugin (via --with-countthreads) to verify that neither
your test, nor the code it tests, leak threads. Unfortunately, this
plugin cannot be enabled by default, since we do have buggy test and
code that do leak.
Change-Id: I4347f5a6ccf02e80d86174c979eb85a0c5076e7a
Signed-off-by: Dan Kenigsberg <danken(a)redhat.com>
---
M tests/testValidation.py
M tests/testlib.py
2 files changed, 22 insertions(+), 1 deletion(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/40/69040/1
diff --git a/tests/testValidation.py b/tests/testValidation.py
index c9b147d..a4b6789 100644
--- a/tests/testValidation.py
+++ b/tests/testValidation.py
@@ -23,6 +23,7 @@
from functools import wraps
from nose.plugins import Plugin
import subprocess
+import threading
class SlowTestsPlugin(Plugin):
@@ -88,6 +89,24 @@
StressTestsPlugin.enabled = True
+class CountThreadsPlugin(Plugin):
+ """
+ Check whether a test (or the code it triggers) leaks threads
+ """
+ name = 'countthreads'
+
+ def _thread_names(self):
+ return frozenset(t.name for t in threading.enumerate())
+
+ def startTest(self, test):
+ self._start_thread_names = self._thread_names()
+
+ def stopTest(self, test):
+ diff = self._thread_names() - self._start_thread_names
+ if diff:
+ raise Exception('thread leak: %s ' % diff)
+
+
def ValidateRunningAsRoot(f):
@wraps(f)
def wrapper(*args, **kwargs):
diff --git a/tests/testlib.py b/tests/testlib.py
index b67b377..8a55e6e 100644
--- a/tests/testlib.py
+++ b/tests/testlib.py
@@ -58,7 +58,8 @@
from virt import vmxml
from monkeypatch import Patch
-from testValidation import SlowTestsPlugin, StressTestsPlugin
+from testValidation import (
+ SlowTestsPlugin, StressTestsPlugin, CountThreadsPlugin)
# /tmp may use tempfs filesystem, not suitable for some of the test assuming a
# filesystem with direct io support.
@@ -433,6 +434,7 @@
plugins=core.DefaultPluginManager())
conf.plugins.addPlugin(SlowTestsPlugin())
conf.plugins.addPlugin(StressTestsPlugin())
+ conf.plugins.addPlugin(CountThreadsPlugin())
runner = VdsmTestRunner(stream=conf.stream,
verbosity=conf.verbosity,
--
To view, visit
https://gerrit.ovirt.org/69040
To unsubscribe, visit
https://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I4347f5a6ccf02e80d86174c979eb85a0c5076e7a
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Dan Kenigsberg <danken(a)redhat.com>