From d306e37e9d1de8bc81206e6b64b2e2b775d3999c Mon Sep 17 00:00:00 2001 From: Jake Moshenko Date: Thu, 12 Feb 2015 16:05:45 -0500 Subject: [PATCH] Add some simple tests to sanity check the time machine gc. --- test/test_gc.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/test/test_gc.py b/test/test_gc.py index 02d14bfb4..4f4f6c95c 100644 --- a/test/test_gc.py +++ b/test/test_gc.py @@ -1,4 +1,5 @@ import unittest +import time from app import app, storage from initdb import setup_database_for_testing, finished_database_for_testing @@ -210,5 +211,34 @@ class TestGarbageColection(unittest.TestCase): self.gcNow(repository) self.assertNotDeleted(repository, 'i1', 'i2', 'i3', 't1', 't2', 't3', 'f1', 'f2') + def test_time_machine_no_gc(self): + """ Repository has two tags with shared images. Deleting the tag should not remove any images + """ + repository = self.createRepository(latest=['i1', 'i2', 'i3'], other=['i1', 'f1']) + self._set_tag_expiration_policy(repository.namespace_user.username, 60*60*24) + + self.deleteTag(repository, 'latest') + self.assertNotDeleted(repository, 'i2', 'i3') + self.assertNotDeleted(repository, 'i1', 'f1') + + def test_time_machine_gc(self): + """ Repository has two tags with shared images. Deleting the second tag should cause the images + for the first deleted tag to gc. + """ + repository = self.createRepository(latest=['i1', 'i2', 'i3'], other=['i1', 'f1']) + + self._set_tag_expiration_policy(repository.namespace_user.username, 1) + + self.deleteTag(repository, 'latest') + self.assertNotDeleted(repository, 'i2', 'i3') + self.assertNotDeleted(repository, 'i1', 'f1') + + time.sleep(2) + + self.deleteTag(repository, 'other') # This will cause the images associated with latest to gc + self.assertDeleted(repository, 'i2', 'i3') + self.assertNotDeleted(repository, 'i1', 'f1') + + if __name__ == '__main__': unittest.main()