From 7f7014862e78bd630afd3b5891d5570b6c674c30 Mon Sep 17 00:00:00 2001 From: Luis Pabon Date: Fri, 10 May 2013 16:17:45 -0400 Subject: object-store: Added busy_wait unit test to Glusterfs.py Change-Id: Ifee5dccd47a3e301812533851c45b9fe853f9b71 Signed-off-by: Luis Pabon Reviewed-on: http://review.gluster.org/4983 Reviewed-by: Peter Portante Tested-by: Peter Portante --- test/unit/common/test_Glusterfs.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'test') diff --git a/test/unit/common/test_Glusterfs.py b/test/unit/common/test_Glusterfs.py index 8f9b9ff..f36f601 100644 --- a/test/unit/common/test_Glusterfs.py +++ b/test/unit/common/test_Glusterfs.py @@ -15,9 +15,13 @@ import unittest import os, fcntl, errno, shutil +import time from tempfile import mkdtemp import gluster.swift.common.Glusterfs as gfs +def mock_os_path_ismount_false(path): + return False + def mock_os_path_ismount(path): return True @@ -30,6 +34,9 @@ def mock_os_system(cmd): def mock_fcntl_lockf(f, *a, **kw): raise IOError(errno.EAGAIN, os.strerror(errno.EAGAIN)) +def mock_time_sleep(secs): + return True + def _init(): global _RUN_DIR, _OS_SYSTEM, _FCNTL_LOCKF global _OS_PATH_ISMOUNT, __GET_EXPORT_LIST @@ -60,6 +67,21 @@ class TestGlusterfs(unittest.TestCase): def setUp(self): _init() + def test_busy_wait_timeout(self): + os.path.ismount = mock_os_path_ismount_false + + # setup time mock + real_time_sleep = time.sleep + time.sleep = mock_time_sleep + + try: + self.assertFalse(gfs._busy_wait("/")) + finally: + time.sleep = real_time_sleep + + def test_busy_wait(self): + self.assertTrue(gfs._busy_wait("/")) + def test_mount(self): try: tmpdir = mkdtemp() -- cgit