Adam Litke has uploaded a new change for review.

Change subject: tests: Skip tests that behave badly when run in parallel
......................................................................

tests: Skip tests that behave badly when run in parallel

A particular test: resourceManagerTests.testStressTest works by spawning lots of
threads to test the resource manager.  Unfortunately, when run in parallel with
other tests (as happens on Jenkins), it can cause spurious errors in comletely
unrelated tests by causing the user to exceed its thread limit.  There is no
real way around this problem other than to skip this test when tests can be
running in parallel.

To achieve this, introduce a new nose plugin (similar to SlowTestsPlugin) that
can be activated by a command line parameter or environment variable.  When
active, tests marked as @nonparalleltest will be skipped.

The environment variable NOSE_SKIP_NONPARALLEL_TESTS should be added to the
Jenkins unit test job.

Change-Id: Id74717584f0c4753cec58cb1b701e7095a735924
Signed-off-by: Adam Litke <a...@us.ibm.com>
---
M tests/resourceManagerTests.py
M tests/testValidation.py
M tests/testrunner.py
3 files changed, 46 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/73/12173/1

diff --git a/tests/resourceManagerTests.py b/tests/resourceManagerTests.py
index c873394..2a3ada0 100644
--- a/tests/resourceManagerTests.py
+++ b/tests/resourceManagerTests.py
@@ -27,7 +27,7 @@
 
 import storage.resourceManager as resourceManager
 from testrunner import VdsmTestCase as TestCaseBase
-from testValidation import slowtest
+from testValidation import slowtest, nonparalleltest
 
 
 class NullResourceFactory(resourceManager.SimpleResourceFactory):
@@ -603,6 +603,7 @@
         resources.pop().release()  # exclusiveReq 3
 
     @slowtest
+    @nonparalleltest
     def testStressTest(self):
         """
         This tests raises thousands of threads and tries to acquire the same
diff --git a/tests/testValidation.py b/tests/testValidation.py
index 5776851..2c8d736 100644
--- a/tests/testValidation.py
+++ b/tests/testValidation.py
@@ -51,6 +51,37 @@
             SlowTestsPlugin.enabled = True
 
 
+class NonParallelTestsPlugin(Plugin):
+    """
+    When running tests concurrently on the same system, this plugin can be used
+    to skip tests that only work properly when run by themselves.
+    """
+    name = 'nonparalleltests'
+    enabled = False
+
+    def add_options(self, parser, env=os.environ):
+        env_opt = 'NOSE_SKIP_NONPARALLEL_TESTS'
+        if env is None:
+            default = False
+        else:
+            default = env.get(env_opt)
+
+        parser.add_option('--without-nonparallel-tests',
+                          action='store_true',
+                          default=default,
+                          dest='disable_nonparallel_tests',
+                          help='Some tests must be run by themselves and ' +
+                               'can cause spurious errors when run in ' +
+                               'parallel.  If running tests in parallel, ' +
+                               'use this option to skip these types of ' +
+                               'tests [%s]' % env_opt)
+
+    def configure(self, options, conf):
+        Plugin.configure(self, options, conf)
+        if options.disable_nonparallel_tests:
+            NonParallelTestsPlugin.enabled = True
+
+
 def ValidateRunningAsRoot(f):
     @wraps(f)
     def wrapper(*args, **kwargs):
@@ -86,6 +117,17 @@
     return wrap
 
 
+def nonparalleltest(f):
+    @wraps(f)
+    def wrapper(*args, **kwargs):
+        if NonParallelTestsPlugin.enabled:
+            raise SkipTest("Non-parallel tests have been disabled")
+
+        return f(*args, **kwargs)
+
+    return wrapper
+
+
 def checkSudo(cmd):
     p = subprocess.Popen(['sudo', '-l', '-n'] + cmd,
                          stdin=subprocess.PIPE, stdout=subprocess.PIPE,
diff --git a/tests/testrunner.py b/tests/testrunner.py
index dfe9885..d999551 100644
--- a/tests/testrunner.py
+++ b/tests/testrunner.py
@@ -36,7 +36,7 @@
     pthreading.monkey_patch()
 
 
-from testValidation import SlowTestsPlugin
+from testValidation import SlowTestsPlugin, NonParallelTestsPlugin
 
 import zombieReaper
 zombieReaper.registerSignalHandler()
@@ -287,6 +287,7 @@
                          workingDir=testdir,
                          plugins=core.DefaultPluginManager())
     conf.plugins.addPlugin(SlowTestsPlugin())
+    conf.plugins.addPlugin(NonParallelTestsPlugin())
 
     runner = VdsmTestRunner(stream=conf.stream,
                             verbosity=conf.verbosity,


--
To view, visit http://gerrit.ovirt.org/12173
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id74717584f0c4753cec58cb1b701e7095a735924
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Adam Litke <a...@us.ibm.com>
_______________________________________________
vdsm-patches mailing list
vdsm-patches@lists.fedorahosted.org
https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches

Reply via email to