From f1f7b14bf61eded6fb660238e56c857222067cdc Mon Sep 17 00:00:00 2001 From: "A. Jesse Jiryu Davis" Date: Tue, 27 Aug 2013 09:00:50 -0400 Subject: [PATCH] Allow MongoClients to be GC'ed after test runs. Work around http://bugs.python.org/issue11798 to reduce max connection count during tests. --- test/test_auth.py | 2 ++ test/test_binary.py | 4 ---- test/test_bson.py | 4 ---- test/test_code.py | 4 ---- test/test_cursor.py | 3 +++ test/test_database.py | 3 +++ test/test_dbref.py | 4 ---- test/test_grid_file.py | 3 +++ test/test_gridfs.py | 3 +++ test/test_json_util.py | 3 +++ test/test_master_slave_connection.py | 1 + test/test_objectid.py | 4 ---- test/test_pooling_base.py | 1 + test/test_read_preferences.py | 8 ++++---- test/test_son.py | 4 ---- test/test_son_manipulator.py | 3 +++ test/test_timestamp.py | 4 ---- 17 files changed, 26 insertions(+), 32 deletions(-) diff --git a/test/test_auth.py b/test/test_auth.py index 5231c3167..65ce5bf54 100644 --- a/test/test_auth.py +++ b/test/test_auth.py @@ -217,6 +217,7 @@ class TestAuthURIOptions(unittest.TestCase): self.client.pymongo_test.system.users.remove() self.client.admin.system.users.remove() self.client.admin.logout() + self.client = None def test_uri_options(self): # Test default to admin @@ -289,6 +290,7 @@ class TestDelegatedAuth(unittest.TestCase): self.client.pymongo_test2.foo.remove() self.client.admin.system.users.remove() self.client.admin.logout() + self.client = None def test_delegated_auth(self): self.client.admin.authenticate('admin', 'pass') diff --git a/test/test_binary.py b/test/test_binary.py index 655ee449c..5afe4210e 100644 --- a/test/test_binary.py +++ b/test/test_binary.py @@ -37,10 +37,6 @@ from test.test_client import get_client class TestBinary(unittest.TestCase): - - def setUp(self): - pass - def test_binary(self): a_string = "hello world" a_binary = Binary(b("hello world")) diff --git a/test/test_bson.py b/test/test_bson.py index a8448aadc..680662eac 100644 --- a/test/test_bson.py +++ b/test/test_bson.py @@ -53,10 +53,6 @@ PY3 = sys.version_info[0] == 3 class TestBSON(unittest.TestCase): - - def setUp(self): - pass - def test_basic_validation(self): self.assertRaises(TypeError, is_valid, 100) self.assertRaises(TypeError, is_valid, u"test") diff --git a/test/test_code.py b/test/test_code.py index fe5853f3d..767bc275a 100644 --- a/test/test_code.py +++ b/test/test_code.py @@ -22,10 +22,6 @@ from bson.code import Code class TestCode(unittest.TestCase): - - def setUp(self): - pass - def test_types(self): self.assertRaises(TypeError, Code, 5) self.assertRaises(TypeError, Code, None) diff --git a/test/test_cursor.py b/test/test_cursor.py index 0fad5c0b8..6924a9b09 100644 --- a/test/test_cursor.py +++ b/test/test_cursor.py @@ -40,6 +40,9 @@ class TestCursor(unittest.TestCase): def setUp(self): self.db = Database(get_client(), "pymongo_test") + def tearDown(self): + self.db = None + def test_explain(self): a = self.db.test.find() b = a.explain() diff --git a/test/test_database.py b/test/test_database.py index 40512d1f8..0726dbf51 100644 --- a/test/test_database.py +++ b/test/test_database.py @@ -50,6 +50,9 @@ class TestDatabase(unittest.TestCase): def setUp(self): self.client = get_client() + def tearDown(self): + self.client = None + def test_name(self): self.assertRaises(TypeError, Database, self.client, 4) self.assertRaises(InvalidName, Database, self.client, "my db") diff --git a/test/test_dbref.py b/test/test_dbref.py index 4fe680304..0b147ddc3 100644 --- a/test/test_dbref.py +++ b/test/test_dbref.py @@ -28,10 +28,6 @@ from copy import deepcopy class TestDBRef(unittest.TestCase): - - def setUp(self): - pass - def test_creation(self): a = ObjectId() self.assertRaises(TypeError, DBRef) diff --git a/test/test_grid_file.py b/test/test_grid_file.py index 5571d5240..132b168f3 100644 --- a/test/test_grid_file.py +++ b/test/test_grid_file.py @@ -46,6 +46,9 @@ class TestGridFile(unittest.TestCase): self.db.fs.files.remove({}) self.db.fs.chunks.remove({}) + def tearDown(self): + self.db = None + def test_basic(self): f = GridIn(self.db.fs, filename="test") f.write(b("hello world")) diff --git a/test/test_gridfs.py b/test/test_gridfs.py index 4ebf10e00..bcb6831e7 100644 --- a/test/test_gridfs.py +++ b/test/test_gridfs.py @@ -80,6 +80,9 @@ class TestGridfs(unittest.TestCase): self.fs = gridfs.GridFS(self.db) self.alt = gridfs.GridFS(self.db, "alt") + def tearDown(self): + self.db = self.fs = self.alt = None + def test_gridfs(self): self.assertRaises(TypeError, gridfs.GridFS, "foo") self.assertRaises(TypeError, gridfs.GridFS, self.db, 5) diff --git a/test/test_json_util.py b/test/test_json_util.py index c4e6b3e3f..6a21ba154 100644 --- a/test/test_json_util.py +++ b/test/test_json_util.py @@ -48,6 +48,9 @@ class TestJsonUtil(unittest.TestCase): self.db = get_client().pymongo_test + def tearDown(self): + self.db = None + def round_tripped(self, doc): return json_util.loads(json_util.dumps(doc)) diff --git a/test/test_master_slave_connection.py b/test/test_master_slave_connection.py index ac39b1199..961593e6c 100644 --- a/test/test_master_slave_connection.py +++ b/test/test_master_slave_connection.py @@ -69,6 +69,7 @@ class TestMasterSlaveConnection(unittest.TestCase, TestRequestMixin): # that make this fail pass + self.master = self.slaves = self.db = self.client = None super(TestMasterSlaveConnection, self).tearDown() def test_types(self): diff --git a/test/test_objectid.py b/test/test_objectid.py index d3247c8e0..1e2c9cfc7 100644 --- a/test/test_objectid.py +++ b/test/test_objectid.py @@ -38,10 +38,6 @@ def oid(x): class TestObjectId(unittest.TestCase): - - def setUp(self): - pass - def test_creation(self): self.assertRaises(TypeError, ObjectId, 4) self.assertRaises(TypeError, ObjectId, 175.0) diff --git a/test/test_pooling_base.py b/test/test_pooling_base.py index b01b6ff4a..c22b438fb 100644 --- a/test/test_pooling_base.py +++ b/test/test_pooling_base.py @@ -337,6 +337,7 @@ class _TestPoolingBase(object): def tearDown(self): self.c.close() + self.c = None if self.use_greenlets: # Undo patch reload(socket) diff --git a/test/test_read_preferences.py b/test/test_read_preferences.py index 519ef09cd..16f57ac7a 100644 --- a/test/test_read_preferences.py +++ b/test/test_read_preferences.py @@ -212,11 +212,11 @@ class TestCommandAndReadPreference(TestReplicaSetClientBase): secondary_acceptable_latency_ms=1000*1000) def tearDown(self): - self.c.close() - # We create a lot of collections and indexes in these tests, so drop - # the database - self._get_client().drop_database('pymongo_test') + # the database. + self.c.drop_database('pymongo_test') + self.c.close() + self.c = None super(TestCommandAndReadPreference, self).tearDown() def executed_on_which_member(self, client, fn, *args, **kwargs): diff --git a/test/test_son.py b/test/test_son.py index cb2596da9..f89559be8 100644 --- a/test/test_son.py +++ b/test/test_son.py @@ -28,10 +28,6 @@ from bson.son import SON class TestSON(unittest.TestCase): - - def setUp(self): - pass - def test_ordered_dict(self): a1 = SON() a1["hello"] = "world" diff --git a/test/test_son_manipulator.py b/test/test_son_manipulator.py index c1e54e7c0..1f53e187c 100644 --- a/test/test_son_manipulator.py +++ b/test/test_son_manipulator.py @@ -35,6 +35,9 @@ class TestSONManipulator(unittest.TestCase): def setUp(self): self.db = Database(get_client(), "pymongo_test") + def tearDown(self): + self.db = None + def test_basic(self): manip = SONManipulator() collection = self.db.test diff --git a/test/test_timestamp.py b/test/test_timestamp.py index d8d4cb8ad..df268215a 100644 --- a/test/test_timestamp.py +++ b/test/test_timestamp.py @@ -26,10 +26,6 @@ from bson.tz_util import utc class TestTimestamp(unittest.TestCase): - - def setUp(self): - pass - def test_timestamp(self): t = Timestamp(123, 456) self.assertEqual(t.time, 123)