← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~wgrant/launchpad/assume-connectability into lp:launchpad

 

William Grant has proposed merging lp:~wgrant/launchpad/assume-connectability into lp:launchpad.

Commit message:
Don't reconnect to the DB multiple times between tests.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~wgrant/launchpad/assume-connectability/+merge/273361

Don't reconnect to the DB multiple times between tests.

Ensuring that the DB is connectable is the fixture's problem, and it's much less of an issue now that the app Storm code is more resilient to the DB going away. If it proves flaky on buildbot, it can be reverted.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~wgrant/launchpad/assume-connectability into lp:launchpad.
=== modified file 'lib/lp/testing/layers.py'
--- lib/lp/testing/layers.py	2013-08-14 11:15:51 +0000
+++ lib/lp/testing/layers.py	2015-10-05 02:07:17 +0000
@@ -747,7 +747,7 @@
         # point for addressing that mismatch.
         cls._db_fixture.tearDown()
         # Bring up the db, so that it is available for other layers.
-        cls._ensure_db()
+        cls._db_fixture.setUp()
 
     @classmethod
     @profiled
@@ -771,28 +771,8 @@
         pass
 
     @classmethod
-    def _ensure_db(cls):
-        cls._db_fixture.setUp()
-        # Ensure that the database is connectable. Because we might have
-        # just created it, keep trying for a few seconds incase PostgreSQL
-        # is taking its time getting its house in order.
-        attempts = 60
-        for count in range(0, attempts):
-            try:
-                cls.connect().close()
-            except psycopg2.Error:
-                if count == attempts - 1:
-                    raise
-                time.sleep(0.5)
-            else:
-                break
-
-    @classmethod
     @profiled
     def testTearDown(cls):
-        # Ensure that the database is connectable
-        cls.connect().close()
-
         cls._db_fixture.tearDown()
 
         # Fail tests that forget to uninstall their database policies.
@@ -804,7 +784,7 @@
         # Reset/bring up the db - makes it available for either the next test,
         # or a subordinate layer which builds on the db. This wastes one setup
         # per db layer teardown per run, but thats tolerable.
-        cls._ensure_db()
+        cls._db_fixture.setUp()
 
     @classmethod
     @profiled


Follow ups