From 590969ea97768b6b3ccbf80aa03407723bca3384 Mon Sep 17 00:00:00 2001 From: Alejandro Cabrera Date: Mon, 2 Dec 2013 15:53:19 -0500 Subject: [PATCH] fix: mongodb tests consume storage like crazy This patchset addresses a problem where _purge_databases wasn't being called in the storage tests for mongodb. This was consuming about ~19GB of storage per full suite run. The problem was caused by _purge_databases not being overridden by the MongodbMixin class. It was a case of the diamond problem in an inheritance graph. Here's the summary: * testing.TestBase defines _purge_databases * ControllerTestBase is a child of testing.TestBase * XControllerTest are children of ControllerTestBase * MongodbTestMixin was a child of object, and reimplements _purge_databases * When MongoXControllerTest was presented with parents: - XControllerTest - MongodbTestMixin The MRO algorithm chose the implementation of _purge_databases that was first presented, in this case, the null implementation provided by testing.TestBase The proposed solution for the time being is to have each of the MongoXControllerTest classes to override the _purge_databases method. Note: subtyping can get very messy. Change-Id: Ia1abc4c6ec682f3d176f2093d45139f45f7ac12a --- .../unit/queues/storage/test_impl_mongodb.py | 33 ++++++++++++------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/tests/unit/queues/storage/test_impl_mongodb.py b/tests/unit/queues/storage/test_impl_mongodb.py index caf96806a..9a861178e 100644 --- a/tests/unit/queues/storage/test_impl_mongodb.py +++ b/tests/unit/queues/storage/test_impl_mongodb.py @@ -32,15 +32,12 @@ from marconi import tests as testing from marconi.tests.queues.storage import base -class MongodbTestMixin(object): +def _cleanup_databases(controller): + databases = (controller.driver.message_databases + + [controller.driver.queues_database]) - def _purge_databases(self): - """Override to clean databases.""" - databases = (self.driver.message_databases + - [self.driver.queues_database]) - - for db in databases: - self.driver.connection.drop_database(db) + for db in databases: + controller.driver.connection.drop_database(db) class MongodbUtilsTest(testing.TestBase): @@ -87,10 +84,13 @@ class MongodbUtilsTest(testing.TestBase): @testing.requires_mongodb -class MongodbDriverTest(testing.TestBase, MongodbTestMixin): +class MongodbDriverTest(testing.TestBase): config_file = 'wsgi_mongodb.conf' + def _purge_databases(self): + _cleanup_databases(self) + def test_db_instance(self): driver = mongodb.DataDriver(self.conf) @@ -103,12 +103,15 @@ class MongodbDriverTest(testing.TestBase, MongodbTestMixin): @testing.requires_mongodb -class MongodbQueueTests(base.QueueControllerTest, MongodbTestMixin): +class MongodbQueueTests(base.QueueControllerTest): driver_class = mongodb.DataDriver config_file = 'wsgi_mongodb.conf' controller_class = controllers.QueueController + def _purge_databases(self): + _cleanup_databases(self) + def _prepare_conf(self): self.config(options.MONGODB_GROUP, database=uuid.uuid4().hex) @@ -140,7 +143,7 @@ class MongodbQueueTests(base.QueueControllerTest, MongodbTestMixin): @testing.requires_mongodb -class MongodbMessageTests(base.MessageControllerTest, MongodbTestMixin): +class MongodbMessageTests(base.MessageControllerTest): driver_class = mongodb.DataDriver config_file = 'wsgi_mongodb.conf' @@ -149,6 +152,9 @@ class MongodbMessageTests(base.MessageControllerTest, MongodbTestMixin): # NOTE(kgriffs): MongoDB's TTL scavenger only runs once a minute gc_interval = 60 + def _purge_databases(self): + _cleanup_databases(self) + def _prepare_conf(self): self.config(options.MONGODB_GROUP, database=uuid.uuid4().hex) @@ -294,12 +300,15 @@ class MongodbMessageTests(base.MessageControllerTest, MongodbTestMixin): @testing.requires_mongodb -class MongodbClaimTests(base.ClaimControllerTest, MongodbTestMixin): +class MongodbClaimTests(base.ClaimControllerTest): driver_class = mongodb.DataDriver config_file = 'wsgi_mongodb.conf' controller_class = controllers.ClaimController + def _purge_databases(self): + _cleanup_databases(self) + def _prepare_conf(self): self.config(options.MONGODB_GROUP, database=uuid.uuid4().hex)