I'm trying to run Django tests in parallel by using:
python manage.py test --keepdb --parallel
But if a test fails, it caused an aborted SQL connection. In MySQL I can see it:
SHOW GLOBAL STATUS LIKE 'Aborted_connects'; -- aborted_connects : 1
And because of that, I keep seeing this error in other tests:
django.db.utils.OperationalError: (2013, "Lost connection to MySQL server at 'reading initial communication packet', system error: 102")
What can I do to avoid this situation? This is an sample traceback of other tests failing:
Using existing test database for alias 'default'...
Traceback (most recent call last):
File "/Applications/PyCharm.app/Contents/helpers/pycharm/django_test_manage.py", line 157, in <module>
utility.execute()
File "/Applications/PyCharm.app/Contents/helpers/pycharm/django_test_manage.py", line 132, in execute
PycharmTestCommand().run_from_argv(self.argv)
File "/Users/dio/.virtualenvs/athena/lib/python2.7/site-packages/django/core/management/commands/test.py", line 30, in run_from_argv
super(Command, self).run_from_argv(argv)
File "/Users/dio/.virtualenvs/athena/lib/python2.7/site-packages/django/core/management/base.py", line 348, in run_from_argv
self.execute(*args, **cmd_options)
File "/Users/dio/.virtualenvs/athena/lib/python2.7/site-packages/django/core/management/commands/test.py", line 74, in execute
super(Command, self).execute(*args, **options)
File "/Users/dio/.virtualenvs/athena/lib/python2.7/site-packages/django/core/management/base.py", line 399, in execute
output = self.handle(*args, **options)
File "/Applications/PyCharm.app/Contents/helpers/pycharm/django_test_manage.py", line 97, in handle
failures = TestRunner(test_labels, **options)
File "/Applications/PyCharm.app/Contents/helpers/pycharm/django_test_runner.py", line 256, in run_tests
extra_tests=extra_tests, **options)
File "/Applications/PyCharm.app/Contents/helpers/pycharm/django_test_runner.py", line 156, in run_tests
return super(DjangoTeamcityTestRunner, self).run_tests(test_labels, extra_tests, **kwargs)
File "/Users/dio/.virtualenvs/athena/lib/python2.7/site-packages/django/test/runner.py", line 532, in run_tests
old_config = self.setup_databases()
File "/Users/dio/code/athena/common/runner.py", line 12, in setup_databases
result = super(CITestSuiteRunner, self).setup_databases()
File "/Users/dio/.virtualenvs/athena/lib/python2.7/site-packages/django/test/runner.py", line 482, in setup_databases
self.parallel, **kwargs
File "/Users/dio/.virtualenvs/athena/lib/python2.7/site-packages/django/test/runner.py", line 726, in setup_databases
serialize=connection.settings_dict.get("TEST", {}).get("SERIALIZE", True),
File "/Users/dio/.virtualenvs/athena/lib/python2.7/site-packages/django/db/backends/base/creation.py", line 56, in create_test_db
self._create_test_db(verbosity, autoclobber, keepdb)
File "/Users/dio/.virtualenvs/athena/lib/python2.7/site-packages/django/db/backends/base/creation.py", line 165, in _create_test_db
with self._nodb_connection.cursor() as cursor:
File "/Users/dio/.virtualenvs/athena/lib/python2.7/site-packages/django/db/backends/base/base.py", line 233, in cursor
cursor = self.make_cursor(self._cursor())
File "/Users/dio/.virtualenvs/athena/lib/python2.7/site-packages/django/db/backends/base/base.py", line 204, in _cursor
self.ensure_connection()
File "/Users/dio/.virtualenvs/athena/lib/python2.7/site-packages/django/db/backends/base/base.py", line 199, in ensure_connection
self.connect()
File "/Users/dio/.virtualenvs/athena/lib/python2.7/site-packages/django/db/utils.py", line 95, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/Users/dio/.virtualenvs/athena/lib/python2.7/site-packages/django/db/backends/base/base.py", line 199, in ensure_connection
self.connect()
File "/Users/dio/.virtualenvs/athena/lib/python2.7/site-packages/django/db/backends/base/base.py", line 171, in connect
self.connection = self.get_new_connection(conn_params)
File "/Users/dio/.virtualenvs/athena/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 264, in get_new_connection
conn = Database.connect(**conn_params)
File "/Users/dio/.virtualenvs/athena/lib/python2.7/site-packages/MySQLdb/__init__.py", line 81, in Connect
return Connection(*args, **kwargs)
File "/Users/dio/.virtualenvs/athena/lib/python2.7/site-packages/MySQLdb/connections.py", line 193, in __init__
super(Connection, self).__init__(*args, **kwargs2)
django.db.utils.OperationalError: (2013, "Lost connection to MySQL server at 'reading initial communication packet', system error: 102")