Commits

Mike Bayer committed c1de009

- Fixes to routines on Windows, including that default unit tests pass,
and an adjustment to the "soft expiration" feature to ensure the
expiration works given windows time.time() behavior.

Comments (0)

Files changed (7)

docs/build/changelog.rst

     .. change::
         :tags: bug
 
+      Fixes to routines on Windows, including that default unit tests pass,
+      and an adjustment to the "soft expiration" feature to ensure the
+      expiration works given windows time.time() behavior.
+
+    .. change::
+        :tags: bug
+
       Added py2.6 compatibility for unsupported ``total_seconds()`` call
       in region.py
 

dogpile/cache/compat.py

 py32 = sys.version_info >= (3, 2)
 py27 = sys.version_info >= (2, 7)
 jython = sys.platform.startswith('java')
+win32 = sys.platform.startswith('win')
 
 try:
     import threading

dogpile/cache/region.py

             ct = value.metadata["ct"]
             if self._soft_invalidated:
                 if ct < self._soft_invalidated:
-                    ct = time.time() - expiration_time
+                    ct = time.time() - expiration_time - .0001
 
             return value.payload, ct
 
                 ct = value.metadata["ct"]
                 if self._soft_invalidated:
                     if ct < self._soft_invalidated:
-                        ct = time.time() - expiration_time
+                        ct = time.time() - expiration_time - .0001
 
                 return value.payload, ct
 

tests/cache/__init__.py

 from nose import SkipTest
 from functools import wraps
 from dogpile.cache import compat
+import time
+
 
 def eq_(a, b, msg=None):
     """Assert a == b, with repr messaging on failure."""
 
 from dogpile.cache.compat import configparser, io
 
+def winsleep():
+    # sleep a for an amount of time
+    # sufficient for windows time.time()
+    # to change
+    if compat.win32:
+        time.sleep(.001)
 
 def requires_py3k(fn):
     @wraps(fn)

tests/cache/test_decorator.py

 #! coding: utf-8
 
 from ._fixtures import _GenericBackendFixture
-from . import eq_, requires_py3k
+from . import eq_, requires_py3k, winsleep
 from unittest import TestCase
 import time
 from dogpile.cache import util, compat
     def test_decorator_expire_callable_zero(self):
         go = self._fixture(expiration_time=lambda: 0)
         eq_(go(1, 2), (1, 1, 2))
+        winsleep()
         eq_(go(1, 2), (2, 1, 2))
+        winsleep()
         eq_(go(1, 2), (3, 1, 2))
 
     def test_explicit_expire(self):

tests/cache/test_memcached_backend.py

 from ._fixtures import _GenericBackendTest, _GenericMutexTest
-from . import eq_
+from . import eq_, winsleep
 from unittest import TestCase
 from threading import Thread
 import time
 from nose import SkipTest
+from dogpile.cache import compat
+
 
 class _TestMemcachedConn(object):
     @classmethod
         for t in threads:
             t.join()
         eq_(canary, [i + 1 for i in range(count)])
-        eq_(MockClient.number_of_clients, 0)
+
+        if compat.py27:
+            eq_(MockClient.number_of_clients, 0)
+        else:
+            eq_(MockClient.number_of_clients, 1)
 
 

tests/cache/test_region.py

 from dogpile.cache import exception
 from dogpile.cache import make_region, register_backend, CacheRegion, util
 from dogpile.cache.proxy import ProxyBackend
-from . import eq_, is_, assert_raises_message, io, configparser
+from . import eq_, is_, assert_raises_message, io, configparser, winsleep
 import time, datetime
 import itertools
 from collections import defaultdict
     def test_hard_invalidate_get(self):
         reg = self._region()
         reg.set("some key", "some value")
+        time.sleep(.1)
         reg.invalidate()
         is_(reg.get("some key"), NO_VALUE)
 
         eq_(reg.get_or_create("some key", creator),
                     "some value 1")
 
+        time.sleep(.1)
         reg.invalidate()
         eq_(reg.get_or_create("some key", creator),
                     "some value 2")
     def test_soft_invalidate_get(self):
         reg = self._region(config_args={"expiration_time": 1})
         reg.set("some key", "some value")
+        time.sleep(.1)
         reg.invalidate(hard=False)
         is_(reg.get("some key"), NO_VALUE)
 
         eq_(reg.get_or_create("some key", creator),
                     "some value 1")
 
+        time.sleep(.1)
         reg.invalidate(hard=False)
         eq_(reg.get_or_create("some key", creator),
                     "some value 2")
         ret = reg.get_or_create_multi(
                     [1, 2], creator)
         eq_(ret, [1, 1])
+        time.sleep(.1)
         reg.invalidate(hard=False)
         ret = reg.get_or_create_multi(
                     [1, 2], creator)
                     should_cache_fn=should_cache_fn)
         eq_(ret, 1)
         eq_(reg.backend._cache['some key'][0], 1)
+        time.sleep(.1)
         reg.invalidate()
         ret = reg.get_or_create(
                     "some key", creator,
                     should_cache_fn=should_cache_fn)
         eq_(ret, [1, 1])
         eq_(reg.backend._cache[1][0], 1)
+        time.sleep(.1)
         reg.invalidate()
         ret = reg.get_or_create_multi(
                     [1, 2], creator,
                     should_cache_fn=should_cache_fn)
         eq_(ret, [2, 2])
         eq_(reg.backend._cache[1][0], 1)
+        time.sleep(.1)
         reg.invalidate()
         ret = reg.get_or_create_multi(
                     [1, 2], creator,