Merge lp:~salgado/launchpad/bug-495544 into lp:launchpad/db-devel

Proposed by Guilherme Salgado
Status: Merged
Approved by: Данило Шеган
Approved revision: not available
Merged at revision: not available
Proposed branch: lp:~salgado/launchpad/bug-495544
Merge into: lp:launchpad/db-devel
Diff against target: 90 lines (+26/-17)
2 files modified
lib/canonical/database/sqlbase.py (+5/-15)
lib/canonical/database/tests/test_zopeless_transaction_manager.py (+21/-2)
To merge this branch: bzr merge lp:~salgado/launchpad/bug-495544
Reviewer Review Type Date Requested Status
Данило Шеган (community) release-critical Approve
Henning Eggers (community) code Approve
Review via email: mp+16120@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Guilherme Salgado (salgado) wrote :

Make ZopelessTransactionManager._reset_stores only reset active stores (e.g. those returned by ZStorm.iterstores) instead of always trying to reset the main-master and auth-master stores.

Revision history for this message
Henning Eggers (henninge) wrote :

Thanks for fixing this!

As discussed on IRC, please use assertContentEqual where appropriate and order assert parameters as "expected, observed" (this reviewer likes that better ;). Also, please rename the two test cases in the file as TestZopelessTransactionManagerNoLayer and TestZopelessTransactionManager.

Cheers,
Henning

review: Approve (code)
Revision history for this message
Данило Шеган (danilo) wrote :

Looks good, we'll want to QA a few scripts (at least the Soyuz ones which failed before due to previous bug fix).

review: Approve (release-critical)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lib/canonical/database/sqlbase.py'
--- lib/canonical/database/sqlbase.py 2009-12-02 11:57:11 +0000
+++ lib/canonical/database/sqlbase.py 2009-12-14 21:29:12 +0000
@@ -341,27 +341,17 @@
341 cls._dbhost = dbhost341 cls._dbhost = dbhost
342 cls._dbuser = dbuser342 cls._dbuser = dbuser
343 cls._isolation = isolation343 cls._isolation = isolation
344 cls._reset_store()344 cls._reset_stores()
345 cls._installed = cls345 cls._installed = cls
346 return cls._installed346 return cls._installed
347347
348 @staticmethod348 @staticmethod
349 def _reset_store():349 def _reset_stores():
350 """Reset the MAIN DEFAULT store.350 """Reset the active stores.
351351
352 This is required for connection setting changes to be made visible.352 This is required for connection setting changes to be made visible.
353
354 Other stores do not need to be reset, as code using other stores
355 or explicit flavors isn't using this compatibility layer.
356 """353 """
357 main_store = _get_sqlobject_store()354 for name, store in getUtility(IZStorm).iterstores():
358 # XXX: salgado, 2009-11-06, bug=253542: The import is here to work
359 # around a particularly convoluted circular import.
360 from canonical.launchpad.webapp.interfaces import (
361 IStoreSelector, AUTH_STORE, DEFAULT_FLAVOR)
362 auth_store = getUtility(IStoreSelector).get(
363 AUTH_STORE, DEFAULT_FLAVOR)
364 for store in [main_store, auth_store]:
365 connection = store._connection355 connection = store._connection
366 if connection._state == storm.database.STATE_CONNECTED:356 if connection._state == storm.database.STATE_CONNECTED:
367 if connection._raw_connection is not None:357 if connection._raw_connection is not None:
@@ -392,7 +382,7 @@
392 assert cls._installed is not None, (382 assert cls._installed is not None, (
393 "ZopelessTransactionManager not installed")383 "ZopelessTransactionManager not installed")
394 config.pop(cls._CONFIG_OVERLAY_NAME)384 config.pop(cls._CONFIG_OVERLAY_NAME)
395 cls._reset_store()385 cls._reset_stores()
396 cls._installed = None386 cls._installed = None
397387
398 @classmethod388 @classmethod
399389
=== modified file 'lib/canonical/database/tests/test_zopeless_transaction_manager.py'
--- lib/canonical/database/tests/test_zopeless_transaction_manager.py 2009-11-06 21:30:29 +0000
+++ lib/canonical/database/tests/test_zopeless_transaction_manager.py 2009-12-14 21:29:12 +0000
@@ -4,14 +4,17 @@
4from textwrap import dedent4from textwrap import dedent
5import unittest5import unittest
66
7import psycopg27from zope.component import getUtility
8
9from storm.zope.interfaces import IZStorm
810
9from canonical.config import config11from canonical.config import config
10from canonical.database.sqlbase import ZopelessTransactionManager12from canonical.database.sqlbase import ZopelessTransactionManager
13from canonical.testing.layers import LaunchpadZopelessLayer
11from lp.testing import TestCase14from lp.testing import TestCase
1215
1316
14class TestZopelessTransactionManager(TestCase):17class TestZopelessTransactionManagerNoLayer(TestCase):
1518
16 def test_initZopeless_connects_to_auth_master_db(self):19 def test_initZopeless_connects_to_auth_master_db(self):
17 # Some scripts might create EmailAddress and Account entries, so20 # Some scripts might create EmailAddress and Account entries, so
@@ -39,5 +42,21 @@
39 # Clean up the configuration42 # Clean up the configuration
40 config.pop('new-db')43 config.pop('new-db')
4144
45
46class TestZopelessTransactionManager(TestCase):
47 layer = LaunchpadZopelessLayer
48
49 def test_reset_stores_only_does_so_on_active_stores(self):
50 active_stores = [item[0] for item in getUtility(IZStorm).iterstores()]
51 self.assertContentEqual(
52 ['launchpad-main-master', 'session'], active_stores)
53 ZopelessTransactionManager._reset_stores()
54 # If any other stores had been reset, they'd be activated and would
55 # then be returned by ZStorm.iterstores().
56 new_active_stores = [
57 item[0] for item in getUtility(IZStorm).iterstores()]
58 self.assertContentEqual(active_stores, new_active_stores)
59
60
42def test_suite():61def test_suite():
43 return unittest.TestLoader().loadTestsFromName(__name__)62 return unittest.TestLoader().loadTestsFromName(__name__)

Subscribers

People subscribed via source and target branches

to status/vote changes: