Permalink
Browse files

Bug 745059 - memcached backend fails to increment total size; r=telliott

  • Loading branch information...
1 parent c6bfc77 commit b3a5f073d070a3625ca8877a98dec3dbcfe8366f @rfk rfk committed Apr 13, 2012
Showing with 15 additions and 5 deletions.
  1. +4 −2 syncstorage/storage/cachemanager.py
  2. +10 −3 syncstorage/tests/test_memcachedsql.py
  3. +1 −0 syncstorage/tests/tests.ini
@@ -84,6 +84,7 @@ def delete(self, key):
raise BackendError(str(err))
def incr(self, key, size=1):
+ size = int(size)
with self.pool.reserve() as mc:
try:
return mc.incr(key, size)
@@ -233,11 +234,12 @@ def flush_user_cache(self, user_id):
# total managment
#
def set_total(self, user_id, total):
+ # we store the size in bytes in memcached
+ total = int(total * _KB)
key = _key(user_id, 'size')
# if this fail it's not a big deal
try:
- # we store the size in bytes in memcached
- self.set(key, total * _KB)
+ self.set(key, total)
except BackendError:
self.logger.error('Could not write to memcached')
@@ -17,14 +17,16 @@
from mozsvc.plugin import load_from_settings
from syncstorage.util import get_timestamp
+from syncstorage.tests.support import StorageTestCase
_UID = 1
_PLD = '*' * 500
-class TestMemcachedSQLStorage(unittest2.TestCase):
+class TestMemcachedSQLStorage(StorageTestCase):
def setUp(self):
+ super(TestMemcachedSQLStorage, self).setUp()
if not MEMCACHED:
raise unittest2.SkipTest
@@ -89,7 +91,7 @@ def test_meta_global(self):
meta = self.storage.cache.get('1:meta:global')
self.assertEquals(meta['id'], 'global')
size = self.storage.cache.get('1:size')
- self.assertEquals(size, 500)
+ self.assertEquals(size, len(_PLD))
# this should remove the cache for meta global
self.storage.delete_item(_UID, 'meta', 'global')
@@ -169,6 +171,11 @@ def test_size(self):
self.storage.cache.delete('%d:size' % _UID)
self.assertEquals(self.storage.get_total_size(_UID), wanted)
+ # adding an item should increment the cached size.
+ self.storage.set_item(_UID, 'foo', '2', payload=_PLD)
+ wanted += len(_PLD) / 1024.
+ self.assertEquals(self.storage.get_total_size(_UID), wanted)
+
def test_collection_stamps(self):
if not self._is_up():
return
@@ -224,7 +231,7 @@ def test_collection_stamps(self):
# until we asked for it again
size = self.storage.get_collection_sizes(1)
- self.assertEqual(self.storage.cache.get('1:size') / 1024,
+ self.assertEqual(self.storage.cache.get('1:size') / 1024.,
sum(size.values()))
def test_collection_sizes(self):
@@ -17,6 +17,7 @@ use_ssl = false
[storage]
backend = syncstorage.storage.sql.SQLStorage
+#backend = syncstorage.storage.memcachedsql.MemcachedSQLStorage
sqluri = sqlite:////tmp/tests.db
#sqluri = pymysql://sync:sync@localhost/sync
standard_collections = false

0 comments on commit b3a5f07

Please sign in to comment.