From 204240222fdf63ba13d20946919549f0a3c374ad Mon Sep 17 00:00:00 2001 From: Peter Portante Date: Mon, 3 Feb 2014 00:42:39 -0500 Subject: [PATCH] Attempt to make test_memcache_pool_timeout stable Too much time can pass after we create a set of co-routines and when the parent co-routine continues is setup and staging. Instead, we perform all the setup and staging, let the system run and then verify the final state after all the dust settles. Change-Id: I801148e380807119d3d6da5a24ba9cced39fb339 Closes-Bug: 1272503 --- test/unit/common/test_memcached.py | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/test/unit/common/test_memcached.py b/test/unit/common/test_memcached.py index bf8d1d2b22..f3df46c404 100644 --- a/test/unit/common/test_memcached.py +++ b/test/unit/common/test_memcached.py @@ -493,31 +493,29 @@ class TestMemcached(unittest.TestCase): io_timeout=0.5, pool_timeout=0.1) - p = GreenPool() - for i in range(10): - p.spawn(memcache_client.set, 'key', 'value') - - # let everyone block - sleep(0) - self.assertEqual(pending['1.2.3.5:11211'], 10) - - # hand out a couple slow connection + # Hand out a couple slow connections to 1.2.3.5, leaving 1.2.3.4 + # fast. All ten (10) clients should try to talk to .5 first, and + # then move on to .4, and we'll assert all that below. mock_conn = MagicMock(), MagicMock() mock_conn[1].sendall = lambda x: sleep(0.2) connections['1.2.3.5:11211'].put(mock_conn) connections['1.2.3.5:11211'].put(mock_conn) - # so far so good, everyone is still waiting - self.assertEqual(pending['1.2.3.5:11211'], 10) - self.assertEqual(len(memcache_client._errors['1.2.3.5:11211']), 0) - - # but they won't wait longer than pool_timeout mock_conn = MagicMock(), MagicMock() connections['1.2.3.4:11211'].put(mock_conn) connections['1.2.3.4:11211'].put(mock_conn) + + p = GreenPool() + for i in range(10): + p.spawn(memcache_client.set, 'key', 'value') + + # Wait for the dust to settle. p.waitall() + + self.assertEqual(pending['1.2.3.5:11211'], 8) self.assertEqual(len(memcache_client._errors['1.2.3.5:11211']), 8) self.assertEqual(served['1.2.3.5:11211'], 2) + self.assertEqual(pending['1.2.3.4:11211'], 0) self.assertEqual(len(memcache_client._errors['1.2.3.4:11211']), 0) self.assertEqual(served['1.2.3.4:11211'], 8)