﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
19343	TransactionTestCase + TEST_MIRROR + multi_db = deadlock	Aymeric Augustin	Aymeric Augustin	"This ticket is split from https://code.djangoproject.com/ticket/18984#comment:5

When `TEST_MIRROR` is used, an empty test case within a `TransactionTestCase` that declares `multi_db = True` deadlocks.

With MySQL, the test runner dies after the third Ctrl-C with the trace below.

{{{
(django-dev)myk@mYk tests % PYTHONPATH=.. ./runtests.py --settings=test_mysql_local test_runner.MirrorDeadlockTest                       ~/Documents/dev/django/tests
Creating test database for alias 'default'...
Creating test database for alias 'other'...
You're going to deadlock, human. MUHAHA.
.^C^C^CE
======================================================================
ERROR: test_teardown_deadlock (regressiontests.test_runner.tests.MirrorDeadlockTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File ""/Users/myk/Documents/dev/django/django/test/testcases.py"", line 478, in __call__
    self._post_teardown()
  File ""/Users/myk/Documents/dev/django/django/test/testcases.py"", line 492, in _post_teardown
    self._fixture_teardown()
  File ""/Users/myk/Documents/dev/django/django/test/testcases.py"", line 517, in _fixture_teardown
    skip_validation=True, reset_sequences=False)
  File ""/Users/myk/Documents/dev/django/django/core/management/__init__.py"", line 160, in call_command
    return klass.execute(*args, **defaults)
  File ""/Users/myk/Documents/dev/django/django/core/management/base.py"", line 252, in execute
    output = self.handle(*args, **options)
  File ""/Users/myk/Documents/dev/django/django/core/management/base.py"", line 382, in handle
    return self.handle_noargs(**options)
  File ""/Users/myk/Documents/dev/django/django/core/management/commands/flush.py"", line 64, in handle_noargs
    transaction.rollback_unless_managed(using=db)
  File ""/Users/myk/Documents/dev/django/django/db/transaction.py"", line 128, in rollback_unless_managed
    connection.rollback_unless_managed()
  File ""/Users/myk/Documents/dev/django/django/db/backends/__init__.py"", line 222, in rollback_unless_managed
    self._rollback()
  File ""/Users/myk/Documents/dev/django/django/db/backends/mysql/base.py"", line 420, in _rollback
    BaseDatabaseWrapper._rollback(self)
  File ""/Users/myk/Documents/dev/django/django/db/backends/__init__.py"", line 58, in _rollback
    return self.connection.rollback()
OperationalError: (2006, 'MySQL server has gone away')

----------------------------------------------------------------------
Ran 1 test in 3.969s

FAILED (errors=1)
Destroying test database for alias 'default'...
Destroying test database for alias 'other'...
}}}

Running the test with PostgreSQL also deadlocks, and refuses to die with Ctrl-C, so I don't have a stack trace.

During the deadlock, `ps` shows:
{{{
postgres: django test_django [local] TRUNCATE TABLE waiting  
postgres: django test_django [local] idle in transaction  
}}}"	Bug	closed	Testing framework	dev	Normal	fixed			Accepted	1	0	0	0	0	0
