Anssi,

Thanks for the review,

On Tue, Jul 10, 2012 at 2:16 AM, Anssi Kääriäinen
<[email protected]> wrote:
>
> I spotted one error:
>   https://github.com/ramiro/django/compare/pr45_t18271#L7R472 - The
> line should say conn.cursor(), not connection.cursor().

Fixed in the last iteration of the branch.

>
> I ran the full test suite on SQLite, and got this error:
> ======================================================================
> ERROR: test_pass_connection_between_threads
> (regressiontests.backends.tests.ThreadTests)
> ----------------------------------------------------------------------
> Traceback (most recent call last):
>   File "/home/akaariai/Programming/django/tests/regressiontests/
> backends/tests.py", line 595, in test_pass_connection_between_threads
>     self.assertTrue(isinstance(exceptions[0], DatabaseError))
> IndexError: list index out of range
>
> I don't know if this is related to this patch or not. The error does
> not happen when running the backends test alone. This might be related
> to test ordering

Exactly, this is what I've found is happening:

The problems shows when you run together (minimal expression):

A. Any test from the servers `regression` tests (that subclass
   TransactiontestCase via LiveServerTestCase)
B. The test that is generating the error: A test from the `backends`
   regression tests (that subclass TestCase)

e.g.

 runtests.py --settings=test_sqlite servers.LiveServerViews.test_404
backends.ThreadTests.test_pass_connection_between_threads

For SQLite, memory-hosted databases, LiveServerTestCase sets main thread's
'default' DB connection's allow_thread_sharing to True.

The `backends` tests:

* Spawns a second helper thread
* It clobbers this thread's connection with the main thread's one.
* Both main and helper threads 'default' connections' allow_`thread_sharing`
  values are initialized or assumed be False and then the effects of such
  value are then verified.

Currently, tests that subclass TestCase always run first so the order is
always B before A and no problem occurs. Even when the main thread default
connection `allow_thread_sharing` value state is preserved across test cases
after all the LiveserverTestCase have finished.

But when the patch is applied such order isn't guaranteed anymore (all the
tests that inherit from unittest.TestCase are run intermixed w/o a defined
orderiing.)

The test discovery seems to always order them so A runs before B, the main
thread connection allow_thread_sharing=True values survives, causes a
condition that isn't expected by the B test and so the error occurs.

Maybe we can fix the LiveServerTestCase so it doesn't leak the munging of
`allow_thread_sharing` it performs by resetting its value in its
classTearDown() method?.


>
> And a question:
>   This change in https://github.com/ramiro/django/compare/pr45_t18271#L9R502
> says that changing a TestCase to TransactionTestCase might solve some
> errors caused by test ordering. I don't get why this is true.

It was text I had moved from a spot below in the same document. It applied to
the changes introduced in 1.1 and is actually inaccurate now. My fault,
I've reworded it.

Regards,

-- 
Ramiro Morales

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en.

Reply via email to