diff options
-rw-r--r-- | openstack/common/rpc/impl_qpid.py | 4 | ||||
-rw-r--r-- | openstack/common/rpc/matchmaker_redis.py | 5 | ||||
-rw-r--r-- | tests/unit/rpc/test_matchmaker_redis.py | 12 |
3 files changed, 11 insertions, 10 deletions
diff --git a/openstack/common/rpc/impl_qpid.py b/openstack/common/rpc/impl_qpid.py index f8339b13..bbfb90f1 100644 --- a/openstack/common/rpc/impl_qpid.py +++ b/openstack/common/rpc/impl_qpid.py @@ -491,10 +491,10 @@ class Connection(object): self.connection.tcp_nodelay = self.conf.qpid_tcp_nodelay def _register_consumer(self, consumer): - self.consumers[str(consumer.get_receiver())] = consumer + self.consumers[hash(consumer.get_receiver())] = consumer def _lookup_consumer(self, receiver): - return self.consumers[str(receiver)] + return self.consumers[hash(receiver)] def reconnect(self): """Handles reconnecting and re-establishing sessions and queues.""" diff --git a/openstack/common/rpc/matchmaker_redis.py b/openstack/common/rpc/matchmaker_redis.py index 10bb106b..bb24ea4b 100644 --- a/openstack/common/rpc/matchmaker_redis.py +++ b/openstack/common/rpc/matchmaker_redis.py @@ -111,7 +111,10 @@ class MatchMakerRedis(mm_common.HeartbeatMatchMakerBase): self.register(self.topic_host[host], host) def is_alive(self, topic, host): - if self.redis.ttl(host) == -1: + ttl = self.redis.ttl(host) + # old python-redis versions returned -1 for Redis, while new + # versions return None, so check both + if ttl is None or ttl == -1: self.expire(topic, host) return False return True diff --git a/tests/unit/rpc/test_matchmaker_redis.py b/tests/unit/rpc/test_matchmaker_redis.py index cdc0f732..e5a47114 100644 --- a/tests/unit/rpc/test_matchmaker_redis.py +++ b/tests/unit/rpc/test_matchmaker_redis.py @@ -102,10 +102,10 @@ class MatchMakerRedisHeartbeatTestCase(test_base.BaseTestCase, self.assertTrue(ttl > -1) def test_expires_hosts(self): - """Tests that hosts expire. + """Tests hosts expiration. Registers a host, ensures it is registered, then waits for it to - expire. Ensures is no longer registered. + expire. Finally, ensures it is no longer registered. """ self.driver.register(self.topic, self.hosts[0]) @@ -115,12 +115,10 @@ class MatchMakerRedisHeartbeatTestCase(test_base.BaseTestCase, eventlet.sleep(ttl + 1) ttl2 = self.driver.redis.ttl(key_host) - # Tests that host has actually expired. - self.assertEqual(ttl2, -1) + # Tests that host has actually expired + self.assertEqual(ttl2, None) - def test_expired_hosts_removed(self): - """Test that expired hosts are removed from results.""" - self.test_expires_hosts() + # Tests that host is removed from results self.assertEqual(self.driver.queues(self.topic), []) |