Commit db7fa9fd by rfkelly0

fix gc-related errors in RemoteFileBuffer tests

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