object-store: Added busy_wait unit test to Glusterfs.py

Change-Id: Ifee5dccd47a3e301812533851c45b9fe853f9b71
Signed-off-by: Luis Pabon <lpabon@redhat.com>
Reviewed-on: http://review.gluster.org/4983
Reviewed-by: Peter Portante <pportant@redhat.com>
Tested-by: Peter Portante <pportant@redhat.com>
This commit is contained in:
Luis Pabon 2013-05-10 16:17:45 -04:00 committed by Peter Portante
parent 952a240852
commit 7f7014862e
2 changed files with 23 additions and 1 deletions

View File

@ -55,7 +55,7 @@ def _busy_wait(full_mount_path):
# Iterate for definite number of time over a given
# interval for successful mount
for i in range(0, 5):
if os.path.ismount(os.path.join(full_mount_path)):
if os.path.ismount(full_mount_path):
return True
time.sleep(2)
logging.error('Busy wait for mount timed out for mount %s', full_mount_path)

View File

@ -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()