diff options
author | Lukas Slebodnik <lslebodn@redhat.com> | 2016-01-13 15:06:06 +0100 |
---|---|---|
committer | Lukas Slebodnik <lslebodn@redhat.com> | 2016-02-02 16:51:47 +0100 |
commit | 9e1de5c83371d91e200254cceef70852f5f94fd2 (patch) | |
tree | 11c85762fb4c59225e0439307b3720ef615c28fc /src/tests | |
parent | 700d45751e997c634504a4f22facd2edf82edea7 (diff) | |
download | sssd-9e1de5c83371d91e200254cceef70852f5f94fd2.tar.gz sssd-9e1de5c83371d91e200254cceef70852f5f94fd2.tar.xz sssd-9e1de5c83371d91e200254cceef70852f5f94fd2.zip |
TESTS: Fix race condition in python test
Python tests for pyhbac and pysss_murmur created symbolic
links in shared directory ".libs". It happened that both
tests created symbolic link in the same time and therefore
python2 test could try to import link to python3 module
which caused failures in tests.
Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
Diffstat (limited to 'src/tests')
-rwxr-xr-x | src/tests/pyhbac-test.py | 33 | ||||
-rwxr-xr-x | src/tests/pysss_murmur-test.py | 33 |
2 files changed, 32 insertions, 34 deletions
diff --git a/src/tests/pyhbac-test.py b/src/tests/pyhbac-test.py index 8fa5169e0..e34f05596 100755 --- a/src/tests/pyhbac-test.py +++ b/src/tests/pyhbac-test.py @@ -5,11 +5,12 @@ import unittest import sys import os import copy -import sys -import errno +import tempfile + +BUILD_DIR = os.getenv('builddir') or "." +TEST_DIR = os.getenv('SSS_TEST_DIR') or "." +MODPATH = tempfile.mkdtemp(prefix="tp_pyhbac_", dir=TEST_DIR) -srcdir = os.getenv('builddir') or "." -MODPATH = srcdir + "/.libs" #FIXME - is there a way to get this from libtool? if sys.version_info[0] > 2: unicode = str @@ -52,22 +53,15 @@ class PyHbacImport(unittest.TestCase): def testImport(self): " Import the module and assert it comes from tree " try: - cwd_backup = os.getcwd() - - try: - os.unlink(MODPATH + "/pyhbac.so") - except OSError as e: - if e.errno == errno.ENOENT: - pass - else: - raise e + dest_module_path = MODPATH + "/pyhbac.so" - os.chdir(MODPATH) if sys.version_info[0] > 2: - os.symlink("_py3hbac.so", "pyhbac.so") + src_module_path = BUILD_DIR + "/.libs/_py3hbac.so" else: - os.symlink("_py2hbac.so", "pyhbac.so") - os.chdir(cwd_backup) + src_module_path = BUILD_DIR + "/.libs/_py2hbac.so" + + src_module_path = os.path.abspath(src_module_path) + os.symlink(src_module_path, dest_module_path) import pyhbac except ImportError as e: @@ -470,6 +464,11 @@ class PyHbacRequestTest(unittest.TestCase): self.assertRaises(TypeError, req.evaluate, (allow_rule, None)) class PyHbacModuleTest(unittest.TestCase): + @classmethod + def tearDownClass(cls): + os.unlink(MODPATH + "/pyhbac.so") + os.rmdir(MODPATH) + def testHasResultTypes(self): assert hasattr(pyhbac, "HBAC_EVAL_ALLOW") assert hasattr(pyhbac, "HBAC_EVAL_DENY") diff --git a/src/tests/pysss_murmur-test.py b/src/tests/pysss_murmur-test.py index d21450a26..7237c95b0 100755 --- a/src/tests/pysss_murmur-test.py +++ b/src/tests/pysss_murmur-test.py @@ -22,11 +22,12 @@ from __future__ import print_function import unittest import sys import os -import copy -import errno +import tempfile + +BUILD_DIR = os.getenv('builddir') or "." +TEST_DIR = os.getenv('SSS_TEST_DIR') or "." +MODPATH = tempfile.mkdtemp(prefix="tp_pysss_murmur_", dir=TEST_DIR) -srcdir = os.getenv('builddir') or "." -MODPATH = srcdir + "/.libs" #FIXME - is there a way to get this from libtool? class PySssMurmurImport(unittest.TestCase): def setUp(self): @@ -43,22 +44,15 @@ class PySssMurmurImport(unittest.TestCase): def testImport(self): " Import the module and assert it comes from tree " try: - cwd_backup = os.getcwd() - - try: - os.unlink(MODPATH + "/pysss_murmur.so") - except OSError as e: - if e.errno == errno.ENOENT: - pass - else: - raise e + dest_module_path = MODPATH + "/pysss_murmur.so" - os.chdir(MODPATH) if sys.version_info[0] > 2: - os.symlink("_py3sss_murmur.so", "pysss_murmur.so") + src_module_path = BUILD_DIR + "/.libs/_py3sss_murmur.so" else: - os.symlink("_py2sss_murmur.so", "pysss_murmur.so") - os.chdir(cwd_backup) + src_module_path = BUILD_DIR + "/.libs/_py2sss_murmur.so" + + src_module_path = os.path.abspath(src_module_path) + os.symlink(src_module_path, dest_module_path) import pysss_murmur except ImportError as e: @@ -67,6 +61,11 @@ class PySssMurmurImport(unittest.TestCase): self.assertEqual(pysss_murmur.__file__, MODPATH + "/pysss_murmur.so") class PySssMurmurTest(unittest.TestCase): + @classmethod + def tearDownClass(cls): + os.unlink(MODPATH + "/pysss_murmur.so") + os.rmdir(MODPATH) + def testExpectedHash(self): hash = pysss_murmur.murmurhash3("S-1-5-21-2153326666-2176343378-3404031434", 41, 0xdeadbeef) self.assertEqual(hash, 93103853) |