89
99
self.assertIsInstance(adapter, FooToBar)
90
100
# The adapter is no longer registered.
91
101
self.assertIs(None, queryAdapter(context, IBar))
104
class TestPGBouncerFixtureWithCA(TestCase):
105
"""PGBouncerFixture reconnect tests for Component Architecture layers.
107
Registered Storm Stores should be reconnected through pgbouncer.
109
layer = LaunchpadZopelessLayer
111
def is_connected(self):
112
# First rollback any existing transaction to ensure we attempt
113
# to reconnect. We currently rollback the store explicitely
114
# rather than call transaction.abort() due to Bug #819282.
115
store = IMasterStore(Person)
119
store.find(Person).first()
121
except DisconnectionError:
124
def test_stop_and_start(self):
125
# Database is working.
126
assert self.is_connected()
128
# And database with the fixture is working too.
129
pgbouncer = PGBouncerFixture()
130
with PGBouncerFixture() as pgbouncer:
131
assert self.is_connected()
133
# pgbouncer is transparant. To confirm we are connecting via
134
# pgbouncer, we need to shut it down and confirm our
135
# connections are dropped.
137
assert not self.is_connected()
139
# If we restart it, things should be back to normal.
141
assert self.is_connected()
143
# Database is still working.
144
assert self.is_connected()
146
def test_stop_no_start(self):
147
# Database is working.
148
assert self.is_connected()
150
# And database with the fixture is working too.
151
with PGBouncerFixture() as pgbouncer:
152
assert self.is_connected()
154
# pgbouncer is transparant. To confirm we are connecting via
155
# pgbouncer, we need to shut it down and confirm our
156
# connections are dropped.
158
assert not self.is_connected()
160
# Database is working again.
161
assert self.is_connected()
164
class TestPGBouncerFixtureWithoutCA(TestCase):
165
"""PGBouncerFixture tests for non-Component Architecture layers."""
166
layer = DatabaseLayer
168
def is_db_available(self):
169
# Direct connection to the DB.
170
con_str = dbconfig.rw_main_master + ' user=launchpad_main'
172
con = psycopg2.connect(con_str)
174
cur.execute("SELECT id FROM Person LIMIT 1")
177
except psycopg2.OperationalError:
180
def test_install_fixture(self):
181
self.assert_(self.is_db_available())
183
with PGBouncerFixture() as pgbouncer:
184
self.assertTrue(self.is_db_available())
187
self.assertFalse(self.is_db_available())
189
# This confirms that we are again connecting directly to the
190
# database, as the pgbouncer process was shutdown.
191
self.assertTrue(self.is_db_available())
193
def test_install_fixture_with_restart(self):
194
self.assert_(self.is_db_available())
196
with PGBouncerFixture() as pgbouncer:
197
self.assertTrue(self.is_db_available())
200
self.assertFalse(self.is_db_available())
203
self.assertTrue(self.is_db_available())
205
# Note that because pgbouncer was left running, we can't confirm
206
# that we are now connecting directly to the database.
207
self.assertTrue(self.is_db_available())