Ticket #18984: 18984-deadlock-test-case-without-multi-db.diff

File 18984-deadlock-test-case-without-multi-db.diff, 1.3 KB (added by Aymeric Augustin, 12 years ago)
  • tests/regressiontests/test_runner/tests.py

    diff --git a/tests/regressiontests/test_runner/tests.py b/tests/regressiontests/test_runner/tests.py
    index c723f16..3f46465 100644
    a b class AutoIncrementResetTest(TransactionTestCase):  
    279279    def test_autoincrement_reset2(self):
    280280        p = Person.objects.create(first_name='Jack', last_name='Smith')
    281281        self.assertEqual(p.pk, 1)
     282
     283
     284class MirrorDeadlockTest(TransactionTestCase):
     285
     286    def test_teardown_deadlock(self):
     287        # This test only makes sense if your DATABASES setting uses TEST_MIRROR as follows.
     288        from django.conf import settings
     289        default = settings.DATABASES['default'].copy()
     290        mirror = settings.DATABASES['mirror'].copy()
     291        self.assertEqual(default.pop('TEST_MIRROR'), None)
     292        self.assertEqual(mirror.pop('TEST_MIRROR'), 'default')
     293        self.assertEqual(mirror, default)
     294        # A raw SQL query will bypass Django's transaction management and leave a pending transaction.
     295        db.connections['default'].cursor().execute('INSERT INTO test_runner_person (first_name, last_name) VALUES ("Adrian", "Holovaty")')
     296        db.connections['mirror'].cursor().execute('INSERT INTO test_runner_person (first_name, last_name) VALUES ("Jacob", "Kaplan-Moss")')
Back to Top