Commit 076bef55 by rfkelly0

enable explicit locking in ThreadingTestCase tests

parent 924df19c
...@@ -43,6 +43,8 @@ class FSTestCases: ...@@ -43,6 +43,8 @@ class FSTestCases:
def test_root_dir(self): def test_root_dir(self):
self.assertTrue(self.fs.isdir("")) self.assertTrue(self.fs.isdir(""))
self.assertTrue(self.fs.isdir("/")) self.assertTrue(self.fs.isdir("/"))
self.assertTrue(self.fs.getinfo(""))
self.assertTrue(self.fs.getinfo("/"))
def test_debug(self): def test_debug(self):
str(self.fs) str(self.fs)
...@@ -327,7 +329,7 @@ class FSTestCases: ...@@ -327,7 +329,7 @@ class FSTestCases:
makefile("a/3.txt") makefile("a/3.txt")
self.fs.makedir("a/foo/bar", recursive=True) self.fs.makedir("a/foo/bar", recursive=True)
makefile("a/foo/bar/baz.txt") makefile("a/foo/bar/baz.txt")
self.fs.copydir("a", "copy of a") self.fs.copydir("a", "copy of a")
self.assert_(check("copy of a/1.txt")) self.assert_(check("copy of a/1.txt"))
self.assert_(check("copy of a/2.txt")) self.assert_(check("copy of a/2.txt"))
...@@ -458,9 +460,17 @@ class FSTestCases: ...@@ -458,9 +460,17 @@ class FSTestCases:
class ThreadingTestCases: class ThreadingTestCases:
"""Testcases for thread-safety of FS implementations.""" """Testcases for thread-safety of FS implementations."""
_ThreadingTestCasesLock = threading.RLock()
def _yield(self): def _yield(self):
time.sleep(0.01) time.sleep(0.01)
def _lock(self):
self._ThreadingTestCasesLock.acquire()
def _unlock(self):
self._ThreadingTestCasesLock.release()
def _makeThread(self,func,errors): def _makeThread(self,func,errors):
def runThread(): def runThread():
try: try:
...@@ -532,6 +542,7 @@ class ThreadingTestCases: ...@@ -532,6 +542,7 @@ class ThreadingTestCases:
class RunFSTestCases(unittest.TestCase,FSTestCases): class RunFSTestCases(unittest.TestCase,FSTestCases):
"""Run all FSTestCases against a subdir of self.fs""" """Run all FSTestCases against a subdir of self.fs"""
def __init__(this,subdir): def __init__(this,subdir):
this.subdir = subdir
for meth in dir(this): for meth in dir(this):
if not meth.startswith("test_"): if not meth.startswith("test_"):
continue continue
...@@ -543,6 +554,8 @@ class ThreadingTestCases: ...@@ -543,6 +554,8 @@ class ThreadingTestCases:
this.fs = self.fs.opendir(subdir) this.fs = self.fs.opendir(subdir)
self._yield() self._yield()
getattr(this,meth)() getattr(this,meth)()
def check(this,p):
return self.check(pathjoin(this.subdir,relpath(p)))
def thread1(): def thread1():
RunFSTestCases("thread1") RunFSTestCases("thread1")
def thread2(): def thread2():
...@@ -588,7 +601,7 @@ class ThreadingTestCases: ...@@ -588,7 +601,7 @@ class ThreadingTestCases:
self._runThreads(makedir,removedir) self._runThreads(makedir,removedir)
if self.fs.isdir("testdir"): if self.fs.isdir("testdir"):
self.assertEquals(len(errors),1) self.assertEquals(len(errors),1)
self.assertTrue(isinstance(errors[0]),ResourceNotFoundError) self.assertTrue(isinstance(errors[0],ResourceNotFoundError))
self.fs.removedir("testdir") self.fs.removedir("testdir")
else: else:
self.assertEquals(len(errors),0) self.assertEquals(len(errors),0)
......
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