On Feb 25, 9:24 am, Jeremy Dunck <jdu...@gmail.com> wrote: > I have a master and a replica. In test, the TEST_MIRROR on the > replica points to master. I make writes to master, then read from > replica, then assert some numbers. > > def test_stuff(self): > Foo.objects.using('master').create() > number_received = do_expensive_computations() > # Down in some guts somewhere else, a query is called like so: > # Foo.objects.using('replica').count() > > And that number bubbles up eventually > assertEqual(number_received, 1) > > And this fails because the master has written, but it's in a pending > transaction (enforced by TestCase as a perf optimization). > > I'm not trying to test the consistency here, I'm just trying to test > that that code over there is correctly aggregating previous data. > > I understand the usefulness of the TestCase perf, and I could use > TransactionTestCase, but again, I'm not trying to test transactions. > This will affect a bunch of my code (i.e. many of my tests would have > to be TransactionTestCase). > > I'd like the TEST_MIRROR'd replica to have visibility to master > writes. Right now, a new connection is opened for each alias. It > seems to me that it would be appropriate to share the connection on > TEST_MIRROR'd DBs. I can see that this would cause trouble if you > *wanted* to test against the visibility window, though. > > What do people think might be a reasonable solution?
I think you really should use a transactional test case. The reason is that before you do a commit, your writes really should not be visible. Hiding this in testing could lead to hiding bugs. If you want different behavior, you can create your own TestCase subclass which fiddles with the django.db.connections dictionary in class setup and teardown. - Anssi -- You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-developers@googlegroups.com. To unsubscribe from this group, send email to django-developers+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-developers?hl=en.