Commit 2e95197a authored by Mukund Sivaraman's avatar Mukund Sivaraman
Browse files

[1704] Test remove_lock_files()

parent 7c1277b0
......@@ -1138,7 +1138,9 @@ def remove_lock_files():
lpath = os.environ["B10_FROM_SOURCE_LOCALSTATEDIR"]
for f in lockfiles:
os.unlink(lpath + '/' + f)
fname = lpath + '/' + f
if os.path.isfile(fname):
os.unlink(fname)
return
......
......@@ -23,6 +23,7 @@ endif
chmod +x $(abs_builddir)/$$pytest ; \
$(LIBRARY_PATH_PLACEHOLDER) \
PYTHONPATH=$(COMMON_PYTHON_PATH):$(abs_top_srcdir)/src/bin:$(abs_top_builddir)/src/bin/bind10:$(abs_top_builddir)/src/lib/util/io/.libs \
LOCKFILE_TESTPATH=$(abs_top_builddir)/src/bin/bind10/tests/lockfile_test \
BIND10_MSGQ_SOCKET_FILE=$(abs_top_builddir)/msgq_socket \
$(PYCOVERAGE_RUN) $(abs_builddir)/$$pytest || exit ; \
done
......@@ -1463,6 +1463,43 @@ class SocketSrvTest(unittest.TestCase):
self.assertEqual({}, self.__boss._unix_sockets)
self.assertTrue(sock.closed)
class TestFunctions(unittest.TestCase):
def test_remove_lock_files(self):
if not os.path.isdir(os.environ["LOCKFILE_TESTPATH"]):
os.mkdir(os.environ["LOCKFILE_TESTPATH"])
if "B10_FROM_BUILD" in os.environ:
oldenv = os.environ["B10_FROM_BUILD"]
else:
oldenv = None
os.environ["B10_FROM_BUILD"] = os.environ["LOCKFILE_TESTPATH"]
# create lockfiles for the testcase
lockfiles = ["logger_lockfile"]
for f in lockfiles:
fname = os.environ["B10_FROM_BUILD"] + '/' + f
if not os.path.isfile(fname):
open(fname, "w").close()
# first call should clear up all the lockfiles
bind10_src.remove_lock_files()
# check if the lockfiles exist
for f in lockfiles:
fname = os.environ["B10_FROM_BUILD"] + '/' + f
self.assertFalse(os.path.isfile(fname))
# second call should not assert anyway
bind10_src.remove_lock_files()
os.rmdir(os.environ["LOCKFILE_TESTPATH"])
if oldenv is not None:
os.environ["B10_FROM_BUILD"] = oldenv
else:
os.environ.pop("B10_FROM_BUILD")
if __name__ == '__main__':
# store os.environ for test_unchanged_environment
original_os_environ = copy.deepcopy(os.environ)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment