TEST_MIRROR not working?

127 views
Skip to first unread message

Ilya Baryshev

unread,
Oct 25, 2014, 1:21:54 PM10/25/14
to django...@googlegroups.com
Hey all!

I was writing tests for queries that use replica database, so I tried using TEST_MIRROR setting.
TEST_MIRROR promises "connection to slave will be redirected to point at default
As a result, writes to default will appear on slave". Which happens not to be the case for me,
replica queries are not returning expected results.

Is this a bug, or am I missing something?

Here is my example settings:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'testmirror',
        'HOST': '127.0.0.1',
        'PORT': 5432,
    },
    'slave': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'testmirror2',
        'HOST': '127.0.0.1',
        'PORT': 5432,
        'TEST': {
            'MIRROR': 'default'
        }
    }
}

And test that show replica doesn't have same data:

    def test_fixture(self):
        MyModel.objects.create(name=1)
        self.assertEqual(MyModel.objects.using('default').count(),
                         MyModel.objects.using('slave').count())

Example project in github: https://github.com/coagulant/test_mirror
My case can be repeated by simply running python manage.py test

I'm using

Django==1.7.1
psycopg2==2.5.4

Tom Evans

unread,
Oct 26, 2014, 8:19:47 AM10/26/14
to django...@googlegroups.com
This should be 'TEST_MIRROR': 'default'

Cheers

Tom

Ramiro Morales

unread,
Oct 26, 2014, 9:21:06 AM10/26/14
to django...@googlegroups.com

Actually, in 1.7.x both should work.

Ilya: Can you test if using TEST_MIRROR fixes the issue you are seeing?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAFHbX1L%3DU95K4_XreTm%3D2aET3JRPCCeQL1773wgRZ_25eJX7gQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Ilya Baryshev

unread,
Oct 26, 2014, 3:23:08 PM10/26/14
to django...@googlegroups.com
>Ilya: Can you test if using TEST_MIRROR fixes the issue you are seeing?
Both settings have same effect.

I've slightly modified testcase to demonstrate replica queries are not the same as master queries (no fixtures):

    def test_fixture(self):
        MyModel.objects.using('default').create(name=1)
        MyModel.objects.using('slave').create(name=2)
        MyModel.objects.using('slave').create(name=3)
        self.assertEqual(MyModel.objects.using('default').count(),
                         MyModel.objects.using('slave').count())


======================================================================
FAIL: test_fixture (testapp.tests.TestMirror)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/prophet/work/forks/test_mirror/testmirror/testapp/tests.py", line 13, in test_fixture
    MyModel.objects.using('slave').count())
AssertionError: 3 != 2

Ilya Baryshev

unread,
Oct 27, 2014, 4:04:57 PM10/27/14
to django...@googlegroups.com
I ended up opening a ticket https://code.djangoproject.com/ticket/23718 after fining my testcase actually works against Django 1.3.7
Reply all
Reply to author
Forward
0 new messages