Merge "Fix memcache pool client in monkey-patched environments" into stable/rocky

This commit is contained in:
Zuul 2019-04-24 14:14:52 +00:00 committed by Gerrit Code Review
commit 4a43379aa0
2 changed files with 30 additions and 1 deletions

View File

@ -24,6 +24,10 @@ import itertools
import threading
import time
try:
import eventlet
except ImportError:
eventlet = None
import memcache
from oslo_log import log
from six.moves import queue
@ -45,9 +49,17 @@ class _MemcacheClient(memcache.Client):
"""
__delattr__ = object.__delattr__
__getattribute__ = object.__getattribute__
__new__ = object.__new__
__setattr__ = object.__setattr__
# Hack for lp 1812935
if eventlet and eventlet.patcher.is_monkey_patched('thread'):
# NOTE(bnemec): I'm not entirely sure why this works in a
# monkey-patched environment and not with vanilla stdlib, but it does.
def __new__(cls, *args, **kwargs):
return object.__new__(cls)
else:
__new__ = object.__new__
def __del__(self):
pass

View File

@ -145,3 +145,20 @@ class TestMemcacheClientOverrides(test_cache.BaseTestCase):
if field not in ('__dict__', '__weakref__'):
self.assertNotEqual(id(getattr(thread_local, field, None)),
id(getattr(client_class, field, None)))
def test_can_create_with_kwargs(self):
"""Test for lp 1812935
Note that in order to reproduce the bug, it is necessary to add the
following to the top of oslo_cache/tests/__init__.py::
import eventlet
eventlet.monkey_patch()
This should happen before any other imports in that file.
"""
client = _memcache_pool._MemcacheClient('foo', check_keys=False)
# Make sure kwargs are properly processed by the client
self.assertFalse(client.do_check_key)
# Make sure our __new__ override still results in the right type
self.assertIsInstance(client, _memcache_pool._MemcacheClient)