Handle pre-options response errors correctly

This commit is contained in:
Tyler Hobbs
2013-08-15 16:50:21 -05:00
parent fa57293cce
commit 14dc049e69
2 changed files with 7 additions and 5 deletions

View File

@@ -9,7 +9,7 @@ from cassandra.marshal import int8_unpack
from cassandra.decoder import (ReadyMessage, AuthenticateMessage, OptionsMessage,
StartupMessage, ErrorMessage, CredentialsMessage,
QueryMessage, ResultMessage, decode_response,
InvalidRequestException)
InvalidRequestException, SupportedMessage)
log = logging.getLogger(__name__)
@@ -194,6 +194,11 @@ class Connection(object):
def _handle_options_response(self, options_response):
if self.is_defunct:
return
if not isinstance(options_response, SupportedMessage):
log.error("Did not get expected SupportedMessage response; instead, got: %s", options_response)
return
log.debug("Received options response on new Connection from %s" % self.host)
self.supported_cql_versions = options_response.cql_versions
self.remote_supported_compressions = options_response.options['COMPRESSION']

View File

@@ -91,10 +91,7 @@ class LibevConnectionTest(unittest.TestCase):
# make sure it errored correctly
self.assertTrue(c.is_defunct)
self.assertTrue(c.connected_event.is_set())
try:
self.assertTrue(isinstance(c.last_error, ProtocolError))
except AssertionError:
self.assertTrue(isinstance(c.last_error, AttributeError))
self.assertTrue(isinstance(c.last_error, ProtocolError))
def test_error_message_on_startup(self, *args):
c = self.make_connection()