Commit db7fa9fd by rfkelly0

fix gc-related errors in RemoteFileBuffer tests

parent dd808d70
......@@ -592,6 +592,8 @@ class CacheFSMixin(FS):
return True
except StopIteration:
pass
except RuntimeError:
pass
try:
info = self.getinfo(path)
except ResourceNotFoundError:
......@@ -605,6 +607,8 @@ class CacheFSMixin(FS):
return False
except StopIteration:
pass
except RuntimeError:
pass
try:
info = self.getinfo(path)
except ResourceNotFoundError:
......@@ -640,7 +644,7 @@ class CacheFSMixin(FS):
ci = CachedInfo(info)
self.__set_cached_info(cpath,ci)
to_del = []
for nm in self.__cache.iternames(path):
for nm in self.__cache.names(path):
if nm not in names:
to_del.append(nm)
for nm in to_del:
......@@ -697,33 +701,33 @@ class CacheFSMixin(FS):
def rename(self,src,dst):
super(CacheFSMixin,self).rename(src,dst)
with self.__cache_lock:
for (subpath,ci) in self.__cache.iteritems(src):
for (subpath,ci) in self.__cache.items(src):
self.__cache[pathjoin(dst,subpath)] = ci.clone()
self.__cache.clear(src)
def copy(self,src,dst,**kwds):
super(CacheFSMixin,self).copy(src,dst,**kwds)
with self.__cache_lock:
for (subpath,ci) in self.__cache.iteritems(src):
for (subpath,ci) in self.__cache.items(src):
self.__cache[pathjoin(dst,subpath)] = ci.clone()
def copydir(self,src,dst,**kwds):
super(CacheFSMixin,self).copydir(src,dst,**kwds)
with self.__cache_lock:
for (subpath,ci) in self.__cache.iteritems(src):
for (subpath,ci) in self.__cache.items(src):
self.__cache[pathjoin(dst,subpath)] = ci.clone()
def move(self,src,dst,**kwds):
super(CacheFSMixin,self).move(src,dst,**kwds)
with self.__cache_lock:
for (subpath,ci) in self.__cache.iteritems(src):
for (subpath,ci) in self.__cache.items(src):
self.__cache[pathjoin(dst,subpath)] = ci.clone()
self.__cache.clear(src)
def movedir(self,src,dst,**kwds):
super(CacheFSMixin,self).movedir(src,dst,**kwds)
with self.__cache_lock:
for (subpath,ci) in self.__cache.iteritems(src):
for (subpath,ci) in self.__cache.items(src):
self.__cache[pathjoin(dst,subpath)] = ci.clone()
self.__cache.clear(src)
......
......@@ -77,6 +77,7 @@ class TestRemoteFileBuffer(unittest.TestCase, FSTestCases, ThreadingTestCases):
def tearDown(self):
self.fs.close()
self.fakeOff()
def fake_setcontents(self, path, content='', chunk_size=16*1024):
''' Fake replacement for RemoteTempFS setcontents() '''
......@@ -139,6 +140,7 @@ class TestRemoteFileBuffer(unittest.TestCase, FSTestCases, ThreadingTestCases):
f.flush()
# We are on the end of file (and buffer not serve anything anymore)
self.assertEquals(f.read(), '')
f.close()
self.fakeOn()
......@@ -148,6 +150,8 @@ class TestRemoteFileBuffer(unittest.TestCase, FSTestCases, ThreadingTestCases):
self.assertEquals(f.read(), contents[:-5] + u'1234567890')
f.close()
self.fakeOff()
def test_writeonflush(self):
'''
Test 'write_on_flush' switch of RemoteFileBuffer.
......@@ -161,6 +165,9 @@ class TestRemoteFileBuffer(unittest.TestCase, FSTestCases, ThreadingTestCases):
self.assertRaises(self.FakeException, f.flush)
f.write('Second sample text')
self.assertRaises(self.FakeException, f.close)
self.fakeOff()
f.close()
self.fakeOn()
f = self.fs.open('test.txt', 'wb', write_on_flush=False)
f.write('Sample text')
......@@ -168,6 +175,7 @@ class TestRemoteFileBuffer(unittest.TestCase, FSTestCases, ThreadingTestCases):
f.flush()
f.write('Second sample text')
self.assertRaises(self.FakeException, f.close)
self.fakeOff()
def test_flush_and_continue(self):
'''
......
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