Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CassandraBackend error in threads or gevent pool #6147

Merged
merged 4 commits into from
Jun 21, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
44 changes: 44 additions & 0 deletions t/unit/backends/test_cassandra.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ def test_get_task_meta_for(self, *modules):
meta = x._get_task_meta_for('task_id')
assert meta['status'] == states.PENDING

def test_as_uri(self):
from celery.backends import cassandra as mod
mod.cassandra = Mock()

x = mod.CassandraBackend(app=self.app)
x.as_uri()
x.as_uri(include_password=False)
thedrow marked this conversation as resolved.
Show resolved Hide resolved

def test_store_result(self, *modules):
from celery.backends import cassandra as mod
mod.cassandra = Mock()
Expand Down Expand Up @@ -126,6 +134,38 @@ def shutdown(self):
assert x._cluster is None
assert x._session is None

def test_create_result_table(self):
# Tests behavior when session.execute raises
# cassandra.AlreadyExists.
from celery.backends import cassandra as mod

class OTOExc(Exception):
pass

class FaultySession(object):
def __init__(self, *args, **kwargs):
pass

def execute(self, *args, **kwargs):
raise OTOExc()

class DummyCluster(object):

def __init__(self, *args, **kwargs):
pass

def connect(self, *args, **kwargs):
return FaultySession()

mod.cassandra = Mock()
mod.cassandra.cluster = Mock()
mod.cassandra.cluster.Cluster = DummyCluster
mod.cassandra.AlreadyExists = OTOExc

x = mod.CassandraBackend(app=self.app)
x._get_connection(write=True)
assert x._session is not None

def test_init_session(self):
# Tests behavior when Cluster.connect works properly
from celery.backends import cassandra as mod
Expand All @@ -147,6 +187,10 @@ def connect(self, *args, **kwargs):
x._get_connection(write=True)
assert x._session is not None

s = x._session
x._get_connection()
assert s is x._session

def test_auth_provider(self):
# Ensure valid auth_provider works properly, and invalid one raises
# ImproperlyConfigured exception.
Expand Down