Merge lp:~allenap/launchpad/enable-isolation-tests-bug-551751 into lp:launchpad

Proposed by Gavin Panella
Status: Merged
Approved by: Gavin Panella
Approved revision: no longer in the source branch.
Merged at revision: 12267
Proposed branch: lp:~allenap/launchpad/enable-isolation-tests-bug-551751
Merge into: lp:launchpad
Diff against target: 69 lines (+6/-19)
1 file modified
lib/lp/bugs/externalbugtracker/tests/test_isolation.py (+6/-19)
To merge this branch: bzr merge lp:~allenap/launchpad/enable-isolation-tests-bug-551751
Reviewer Review Type Date Requested Status
Aaron Bentley (community) Approve
Review via email: mp+47164@code.launchpad.net

Commit message

[r=abentley][ui=none][bug=551751] Fix ordering issues in TestIsolation.setUp() and re-enable its test methods.

Description of the change

Amends TestIsolation.setUp() - see the comment I've added to the code
- and re-enables the test methods.

To post a comment you must log in.
Revision history for this message
Aaron Bentley (abentley) wrote :

Don't we always need to define test_suite? Assuming we don't, approved.

I don't really understand why store.execute('SELECT 1') solves these issues, though. Is it simply because it's unknown SQL, so Storm conservatively flushes?

review: Approve
Revision history for this message
Gavin Panella (allenap) wrote :

Thank you for the review :)

> Don't we always need to define test_suite? Assuming we don't, approved.

The Zope test runner seems to DTRT now (and many other test runners do too).

> I don't really understand why store.execute('SELECT 1') solves these issues,
> though. Is it simply because it's unknown SQL, so Storm conservatively
> flushes?

The difference is that it now does a "SELECT 1" in every store, not just the first (which might be set to auto-commit). At least one of the stores will be set to SERIALIZABLE isolation. As soon as a query is executed in one of these stores a transaction must be started. I suppose I could execute "BEGIN" instead; maybe that would be clearer. In fact, maybe transaction.begin() would be enough! I wonder if I tried that when I wrote these tests the first time...

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/bugs/externalbugtracker/tests/test_isolation.py'
2--- lib/lp/bugs/externalbugtracker/tests/test_isolation.py 2010-10-03 15:30:06 +0000
3+++ lib/lp/bugs/externalbugtracker/tests/test_isolation.py 2011-01-22 18:03:11 +0000
4@@ -5,8 +5,6 @@
5
6 __metaclass__ = type
7
8-import unittest
9-
10 from psycopg2.extensions import TRANSACTION_STATUS_IDLE
11 from storm.zope.interfaces import IZStorm
12 import transaction
13@@ -24,12 +22,14 @@
14 def createTransaction(self):
15 stores = list(store for _, store in getUtility(IZStorm).iterstores())
16 self.failUnless(len(stores) > 0, "No stores to test.")
17- stores[0].execute('SELECT 1')
18+ # One or more of the stores may be set to auto-commit. The transaction
19+ # status remains unchanged for these stores hence they are not useful
20+ # for these tests, so execute a query in every store; one of them will
21+ # have a transactional state.
22+ for store in stores:
23+ store.execute('SELECT 1')
24
25 def test_gen_store_statuses(self):
26- # XXX: AaronBentley 2010-03-30 bug=551751: Test fails inconsistently.
27- return
28-
29 # All stores are either disconnected or idle when all
30 # transactions have been aborted.
31 transaction.abort()
32@@ -44,9 +44,6 @@
33 for _, status in isolation.gen_store_statuses()))
34
35 def test_is_transaction_in_progress(self):
36- # XXX: AaronBentley 2010-03-30 bug=551751: Test fails inconsistently.
37- return
38-
39 # is_transaction_in_progress() returns False when all
40 # transactions have been aborted.
41 transaction.abort()
42@@ -57,9 +54,6 @@
43 self.failUnless(isolation.is_transaction_in_progress())
44
45 def test_check_no_transaction(self):
46- # XXX: AaronBentley 2010-03-30 bug=551751: Test fails inconsistently.
47- return
48-
49 # check_no_transaction() should be a no-op when there are no
50 # transactions in operation.
51 transaction.abort()
52@@ -72,9 +66,6 @@
53 isolation.check_no_transaction)
54
55 def test_ensure_no_transaction(self):
56- # XXX: AaronBentley 2010-03-30 bug=551751: Test fails inconsistently.
57- return
58-
59 # ensure_no_transaction() is a decorator that raises
60 # TransactionInProgress if a transaction has begun, else it
61 # simply calls the wrapped function.
62@@ -91,7 +82,3 @@
63 # transaction has begun.
64 self.createTransaction()
65 self.assertRaises(isolation.TransactionInProgress, echo)
66-
67-
68-def test_suite():
69- return unittest.TestLoader().loadTestsFromName(__name__)