def testLocking(self): """Make sure lock is deleted after cleanup""" s1 = BobState() with self.assertRaises(BobError): s2 = BobState() s1.finalize() s2 = BobState()
def testStickyLock(self): """Test that we do not crash if lock file cannot be removed""" os.mkdir("ro") os.chdir("ro") s1 = BobState() os.chmod(".", stat.S_IRUSR | stat.S_IXUSR) s1.finalize()
def testPersistence(self): """Smoke test that tings are persisted""" s1 = BobState() s1.setInputHashes("path", b"hash") s1.finalize() s2 = BobState() self.assertEqual(b"hash", s2.getInputHashes("path")) s2.finalize()
def testUncommitted(self): """Uncommitted state must be picked up on next run""" s1 = BobState() s1.setInputHashes("path", b"hash") # simulate hard crash self.unlock() del s1 s2 = BobState() self.assertEqual(b"hash", s2.getInputHashes("path")) s2.finalize()
def testCannotCommit(self): """Unability to commit state is handled gracefully""" os.mkdir("ro") os.chdir("ro") s1 = BobState() s1.setInputHashes("path", b"hash") os.chmod(".", stat.S_IRUSR | stat.S_IXUSR) s1.finalize() os.chmod(".", stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR) self.unlock() os.unlink(".bob-state.pickle.new") s2 = BobState() self.assertEqual(None, s2.getInputHashes("path")) s2.finalize()
def testCorrupt(self): """A corrupted uncommitted state must be discarded""" s1 = BobState() s1.setInputHashes("path", b"hash") s1.finalize() s2 = BobState() s2.setInputHashes("path", b"must-be-discarded") # simulate hard crash and corrupt state self.unlock() del s2 with open(".bob-state.pickle.new", "r+b") as f: f.write(b"garbabe") s3 = BobState() self.assertEqual(b"hash", s3.getInputHashes("path")) s3.finalize()
def testVanishedLock(self): """Test that we do not crash if lock file vanished""" s1 = BobState() self.unlock() s1.finalize()