From 30751b220eb27b65cccf84a97325938b1f4f2673 Mon Sep 17 00:00:00 2001 From: "A. Jesse Jiryu Davis" Date: Mon, 9 Jan 2012 17:04:44 -0800 Subject: [PATCH 1/2] Python2.4 compatibility fix for replica set tests --- test/test_replica_set_connection.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_replica_set_connection.py b/test/test_replica_set_connection.py index 22dde27314..4bc8b76413 100644 --- a/test/test_replica_set_connection.py +++ b/test/test_replica_set_connection.py @@ -73,10 +73,10 @@ def setUp(self): for h in response.get("arbiters", [])]) repl_set_status = conn.admin.command('replSetGetStatus') - primary_info = next( + primary_info = [ m for m in repl_set_status['members'] if m['stateStr'] == 'PRIMARY' - ) + ][0] self.primary = _partition_node(primary_info['name']) else: From bf3fb5fd9d3713c11ae99a45aea37919e69131fb Mon Sep 17 00:00:00 2001 From: "A. Jesse Jiryu Davis" Date: Mon, 9 Jan 2012 17:05:05 -0800 Subject: [PATCH 2/2] Make sure we don't hang in test_operations when connected to a replica set in recovery. --- test/test_replica_set_connection.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/test_replica_set_connection.py b/test/test_replica_set_connection.py index 4bc8b76413..9f46aab6d6 100644 --- a/test/test_replica_set_connection.py +++ b/test/test_replica_set_connection.py @@ -160,6 +160,18 @@ def make_db(base, name): def test_operations(self): c = self._get_connection() + # Check explicitly for a case we've commonly hit in tests: + # a replica set is started with a tiny oplog, a previous + # test does a big insert that leaves the secondaries + # permanently "RECOVERING", and our insert(w=self.w) hangs + # forever. + rs_status = c.admin.command('replSetGetStatus') + members = rs_status['members'] + self.assertFalse( + [m for m in members if m['stateStr'] == 'RECOVERING'], + "Replica set is recovering, try a larger oplogSize next time" + ) + db = c.pymongo_test db.test.remove({}) self.assertEqual(0, db.test.count())