I have been working on a master/slave router library [1] and have run
into some trouble testing a client application of it.

The issue is that TestCase (as designed) holds test db writes in a
transaction, but the read slave connection (which is to the same DB
under TEST_MIRROR) does not have visibility to the changes (at least
in READ COMMITTED isolation).

For example, if I save a model instance to the master and then attempt
to read from the slave, it won't be there because the test transaction
is still pending.

Has anyone else had success testing master/slave with Django?  I think
a solution probably belongs in core.

Options I can see to address this:
   1) change TEST_MIRROR'd aliases to use the same underlying DB
connection while under test
   2) switch all tests to TransactionTestCase
   3) switch isolation visibility under test
   4) give up hitting replicas under test (that is, have an IS_TEST
branch in the router).

Of these ideas, the 1st is the most appealing to me - it'd mean some
jiggery to not repeatedly close/teardown the DB, but otherwise likely
would be transparent.

2) would have a very bad performance impact.
3) would potentially have bad interactions with some applications.
4) would be a doc change but we'd perhaps need a standard way to
indicate the test context - and also the icky feeling of branching
under test in the app code.

If you have other ideas on how to address the problem, I'm happy to hear them.

Would anyone be opposed to me making TEST_MIRROR aliases use the same
underlying conn?

[1] https://github.com/votizen/django-pindb

-- 
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