summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorPatrick Maia <pmaia@thoughtworks.com>2014-09-08 00:08:41 +0000
committerPatrick Maia <pmaia@thoughtworks.com>2014-09-08 00:08:41 +0000
commit9d8e75ba25fcb39e98a49c3ab6e81759d6d468e4 (patch)
treef8d4cd74cdd1e3ab269bdda1ab4ebcac1e6051c8 /service
parent07515ff8b05ea3795fd296e6e29ff1b8d548b47c (diff)
#51 - fixes bug in which TagIndex.remove were not visible to other TagIndex instances
Diffstat (limited to 'service')
-rw-r--r--service/pixelated/adapter/tag_index.py8
-rw-r--r--service/test/adapter/tag_index_test.py9
2 files changed, 15 insertions, 2 deletions
diff --git a/service/pixelated/adapter/tag_index.py b/service/pixelated/adapter/tag_index.py
index 743c74e1..3cdeb1d8 100644
--- a/service/pixelated/adapter/tag_index.py
+++ b/service/pixelated/adapter/tag_index.py
@@ -31,8 +31,7 @@ class TagIndex:
def set(self, tag):
self.db[tag.name] = tag.as_json_string()
- self.close_db() # force flush
- self.db = dbm.open(self.db_path, 'c')
+ self._flush()
def add(self, tag):
if tag.name not in self.db:
@@ -47,6 +46,7 @@ class TagIndex:
def remove(self, tag_name):
if tag_name in self.db:
del self.db[tag_name]
+ self._flush()
def empty(self):
return len(self.db.keys()) == 0
@@ -56,3 +56,7 @@ class TagIndex:
def close_db(self):
self.db.close()
+
+ def _flush(self):
+ self.close_db()
+ self.db = dbm.open(self.db_path, 'c')
diff --git a/service/test/adapter/tag_index_test.py b/service/test/adapter/tag_index_test.py
index 7667e8e2..515c9571 100644
--- a/service/test/adapter/tag_index_test.py
+++ b/service/test/adapter/tag_index_test.py
@@ -76,3 +76,12 @@ class TestTagIndex(unittest.TestCase):
def test_remove_does_not_raises_exception_if_key_is_not_present(self):
self.tag_index.remove('not_there')
+
+ def test_removals_are_visible_between_instances_using_same_file(self):
+ tag = Tag('some_tag')
+ self.tag_index.set(tag)
+
+ other_tag_index = TagIndex(self.db_path)
+ other_tag_index.remove('some_tag')
+
+ self.assertIsNone(self.tag_index.get('some_tag'))