Created
March 17, 2016 23:54
-
-
Save pkoch/b3127c184ee55198a80a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
commit ab936ee7223dc2fff4202c8b188f7c76089837d9 | |
Author: Paulo Koch <pkoch@yelp.com> | |
Date: Thu Mar 17 16:51:33 2016 -0700 | |
fixup! Disambiguate packages with same filename | |
diff --git a/pypicloud/cache/dynamo.py b/pypicloud/cache/dynamo.py | |
index 1046312..82a895d 100644 | |
--- a/pypicloud/cache/dynamo.py | |
+++ b/pypicloud/cache/dynamo.py | |
@@ -34,10 +34,16 @@ def _path_depth(package): | |
def _decide_between_versions(contender, current): | |
- """Decide between packages with the same filename on different paths.""" | |
+ """Decide between packages with the same filename on different paths. | |
+ | |
+ The earliest one wins. If they both have the same last_modified, prefer the | |
+ one closer to the root. | |
+ """ | |
if contender.last_modified < current.last_modified: | |
return contender | |
+ if current.last_modified < contender.last_modified: | |
+ return current | |
if _path_depth(contender) < _path_depth(current): | |
return contender | |
diff --git a/tests/test_cache.py b/tests/test_cache.py | |
index ae1ce90..8fe5afe 100644 | |
--- a/tests/test_cache.py | |
+++ b/tests/test_cache.py | |
@@ -713,16 +713,19 @@ class TestDynamoCache(unittest.TestCase): | |
) | |
def test_reload_same_filename_different_paths(self): | |
- """ Given two packages with the same filename, use the shortest path. """ | |
+ """ Given two packages with the same filename and same last_modified, | |
+ use the shortest path. """ | |
+ filename = 'here.tgz' | |
now = datetime.utcnow().replace(tzinfo=UTC) | |
pkgs = [ | |
make_package( | |
+ filename=filename, | |
path=p, | |
last_modified=now, | |
factory=DynamoPackage) | |
for p in ( | |
- 'here.tgz', | |
- 'somewhere/far/from/here.tgz', | |
+ filename, | |
+ 'somewhere/far/from/' + filename, | |
) | |
] | |
@@ -734,11 +737,34 @@ class TestDynamoCache(unittest.TestCase): | |
self.assertDictEqual( | |
pkgs[0].data, | |
- self.engine.scan(DynamoPackage).all()[0].data, | |
+ self.db.fetch(filename).data, | |
) | |
- self.assertEqual( | |
- self._summaries(pkgs[0]), | |
- self.db.summary(), | |
+ | |
+ def test_reload_same_filename_later_contender(self): | |
+ """Given two packages with the same filename, use the earliest one.""" | |
+ # Since we didn't set last_modified, these will have ascending dates. | |
+ # That means the first one always wins. | |
+ filename = 'carrot-1.0.tgz' | |
+ pkgs = [ | |
+ make_package( | |
+ filename=filename, | |
+ path=p, | |
+ factory=DynamoPackage) | |
+ for p in ( | |
+ '0/' + filename, | |
+ '1/' + filename, | |
+ ) | |
+ ] | |
+ | |
+ for p in pkgs: | |
+ self.db.clear_all() | |
+ self._save_pkgs(p) | |
+ self.storage.list.return_value = pkgs | |
+ self.db.reload_from_storage() | |
+ | |
+ self.assertDictEqual( | |
+ pkgs[0].data, | |
+ self.db.fetch(filename).data, | |
) | |
def test_reload_clobber_package_save(self): |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment