def test11_purge_multDirMultElement(self): 'QueueSimple.purge() multiple directories & elements' qs = QueueSimple(self.qdir, granularity=1) qs.add('foo') assert qs.count() == 1 time.sleep(2) qs.add('bar') assert qs.count() == 2 assert len(os.listdir(self.qdir)) == 2 qs.purge() assert qs.count() == 2 elem = qs.first() qs.lock(elem) qs.remove(elem) assert qs.count() == 1 qs.purge() assert len(os.listdir(self.qdir)) == 1 time.sleep(2) qs.add('baz') assert len(os.listdir(self.qdir)) == 2 for elem in qs: qs.lock(elem) elem1 = qs.first() lock_path1 = self.qdir + '/' + elem1 + LOCKED_SUFFIX assert os.path.exists(lock_path1) is True os.utime(lock_path1, (time.time() - 25, time.time() - 25)) qs.purge(maxlock=10) assert os.path.exists(lock_path1) is False elem2 = qs.next() lock_path2 = self.qdir + '/' + elem2 + LOCKED_SUFFIX assert os.path.exists(lock_path2) is True
def test10_purge_oneDirOneElement(self): 'QueueSimple.purge() one directory & element' qs = QueueSimple(self.qdir) qs.add('foo') self.assertEqual(qs.count(), 1) elem = qs.first() qs.lock(elem) elem_path_lock = self.qdir + '/' + elem + LOCKED_SUFFIX self.assert_(os.path.exists(elem_path_lock) is True) time.sleep(2) qs.purge(maxlock=1) self.assert_(os.path.exists(elem_path_lock) is False) self.assertEqual(qs.count(), 1) self.assertEqual(len(os.listdir(self.qdir)), 1)