django app cannot connect to cassandra when run with coverage · Issue #445 · nedbat/coveragepy (original) (raw)

Originally reported by Reetesh Ranjan (Bitbucket: reeteshranjan, GitHub: reeteshranjan)


We have a django app that talks with 2 DBs - postgresql and cassandra. Though the django app's runserver starts up fine and work (with ./manage.py runserver) as well as we have a gunicorn+nginx setup that works fine, when I try to measure coverage using a command like this:

coverage run --source='.' manage.py runserver

things don't work as the django app bails out with connection failure with cassandra.

Nothing changes across running with coverage or running normally. Cassandra server has not stopped across these 2 ways of running the server. Is there some issue with authentication that cannot be taken care when running with coverage. All the auth is anyway in the django settings, and there is no hack or anything that goes beyond django structure.

Here is the trace of the failure:

$ coverage run --source=. manage.py runserver
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 312, in execute
    django.setup()
  File "/usr/local/lib/python2.7/dist-packages/django/__init__.py", line 18, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py", line 108, in populate
    app_config.import_models(all_models)
  File "/usr/local/lib/python2.7/dist-packages/django/apps/config.py", line 198, in import_models
    self.models_module = import_module(models_module_name)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/usr/local/lib/python2.7/dist-packages/django_cassandra_engine/models.py", line 12, in <module>
    cassandra_connection.connect()
  File "/usr/local/lib/python2.7/dist-packages/django_cassandra_engine/base/__init__.py", line 94, in connect
    self.connection = CassandraConnection(**settings)
  File "/usr/local/lib/python2.7/dist-packages/django_cassandra_engine/connection.py", line 53, in __init__
    self.setup()
  File "/usr/local/lib/python2.7/dist-packages/django_cassandra_engine/connection.py", line 60, in setup
    connection.setup(self.hosts, self.keyspace, **self.connection_options)
  File "/usr/local/lib/python2.7/dist-packages/cassandra/cqlengine/connection.py", line 131, in setup
    session = cluster.connect()
  File "/usr/local/lib/python2.7/dist-packages/cassandra/cluster.py", line 847, in connect
    self.control_connection.connect()
  File "/usr/local/lib/python2.7/dist-packages/cassandra/cluster.py", line 2083, in connect
    self._set_new_connection(self._reconnect_internal())
  File "/usr/local/lib/python2.7/dist-packages/cassandra/cluster.py", line 2118, in _reconnect_internal
    raise NoHostAvailable("Unable to connect to any servers", errors)
NoHostAvailable: ('Unable to connect to any servers', {'127.0.0.1': OperationTimedOut('errors=Timed out creating connection (5 seconds), last_host=None',)})

And here is how it works fine without coverage:

$ ./manage.py runserver
Performing system checks...

System check identified no issues (0 silenced).
November 12, 2015 - 10:52:50
Django version 1.8.3, using settings 'sweatt.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

I have installed the coverage tool today and I can see the version to be 4.0.2 as in /usr/local/bin/coverage, /usr/local/bin/coverage2 and /usr/local/bin/coverage-2.7.

I am using ubuntu 14.04 and python 2.7.