未验证 提交 592535b8 编写于 作者: L Lukáš Doktor

Merging pull request 1399

* https://github.com/avocado-framework/avocado:
  avocado.utils.filelock: add a functional test
  Makefile: add target for tests that take a long time to run
......@@ -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
......
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()
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册