diff --git a/Makefile b/Makefile index 36c659e3837c1aa1de3fd527840f14a87a48d450..6fbf7f23206d95738dcf9f1c8b1ee84103105edb 100644 --- a/Makefile +++ b/Makefile @@ -28,6 +28,7 @@ all: @echo @echo "Development related targets:" @echo "check: Runs tree static check, unittests and functional tests" + @echo "check-long: Runs tree static check, unittests and long functional tests" @echo "develop: Runs 'python setup.py --develop on this tree alone" @echo "link: Runs 'python setup.py --develop' in all subprojects and links the needed resources" @echo "clean: Get rid of scratch, byte files and removes the links to other subprojects" @@ -156,6 +157,10 @@ check: clean develop check_cyclical modules_boundaries selftests/checkall selftests/check_tmp_dirs +check-long: clean develop check_cyclical modules_boundaries + AVOCADO_CHECK_LONG=1 selftests/checkall + selftests/check_tmp_dirs + selfcheck: clean check_cyclical modules_boundaries AVOCADO_SELF_CHECK=1 selftests/checkall selftests/check_tmp_dirs diff --git a/selftests/functional/test_utils.py b/selftests/functional/test_utils.py index c2fa1a6ffbd35beab66c698f876043836eb00817..3789af6d5fcd57d1434dd7ba591a3fe1e5f6b5a6 100644 --- a/selftests/functional/test_utils.py +++ b/selftests/functional/test_utils.py @@ -1,9 +1,15 @@ +import multiprocessing import os -import sys +import random +import shutil import stat -import time +import sys import tempfile -import shutil +import time + +from avocado.utils.filelock import FileLock +from avocado.utils.stacktrace import prepare_exc_info + if sys.version_info[:2] == (2, 6): import unittest2 as unittest @@ -155,5 +161,37 @@ class ProcessTest(unittest.TestCase): def tearDown(self): shutil.rmtree(self.base_logdir) + +def file_lock_action(args): + path, players = args + max_individual_timeout = 0.021 + max_timeout = max_individual_timeout * players + with FileLock(path, max_timeout): + sleeptime = random.random() / 100 + time.sleep(sleeptime) + + +class FileLockTest(unittest.TestCase): + + def setUp(self): + self.tmpdir = tempfile.mkdtemp(prefix='avocado_' + __name__) + + @unittest.skipIf(os.environ.get("AVOCADO_CHECK_LONG") != "1", + "Skipping test that takes a long time to run") + def test_filelock(self): + players = 1000 + pool = multiprocessing.Pool(players) + args = [(self.tmpdir, players)] * players + try: + pool.map(file_lock_action, args) + except: + msg = 'Failed to run FileLock with %s players:\n%s' + msg %= (players, prepare_exc_info(sys.exc_info())) + self.fail(msg) + + def tearDown(self): + shutil.rmtree(self.tmpdir) + + if __name__ == '__main__': unittest.main()