Fixed 'client connection lost' bug in test_helper

When running tests that add data to datastores (such as replication)
an error can occur if the database is restarted during the test
(as is the case with MySQL).  Since the client is cached, this
would cause the connection to be closed, resulting in a failure.

Since creating the client connection is very quick and we don't need
to do it often, the solution was to not cache the client and just
create a new connection each time.

An error message was also updated to make it more clear if a
datastore-specific helper class used to load data couldn't be
imported correctly.

Change-Id: I90daa9efdeadecfee5231ead0f8b19bb0cbf560d
This commit is contained in:
Peter Stachowski 2016-01-06 14:41:10 -05:00
parent 0f3c41f51c
commit 99baad8d93
1 changed files with 9 additions and 11 deletions

View File

@ -83,9 +83,6 @@ class TestHelper(object):
self._expected_override_name = expected_override_name
self._ds_client = None
self._current_host = None
# For building data access functions
# name/fn pairs for each action
self._data_fns = {self.FN_ADD: {},
@ -121,11 +118,11 @@ class TestHelper(object):
# Client related
################
def get_client(self, host, *args, **kwargs):
"""Gets the datastore client."""
if not self._ds_client or self._current_host != host:
self._ds_client = self.create_client(host, *args, **kwargs)
self._current_host = host
return self._ds_client
"""Gets the datastore client. This isn't cached as the
database may be restarted in between calls, causing
lost connection errors.
"""
return self.create_client(host, *args, **kwargs)
def create_client(self, host, *args, **kwargs):
"""Create a datastore client."""
@ -210,11 +207,12 @@ class TestHelper(object):
def data_fn(self, data_label, data_start, data_size, host,
*args, **kwargs):
# default action is to skip the test
using_str = ''
cls_str = ''
if self._expected_override_name != self.__class__.__name__:
using_str = ' (using %s)' % self.__class__.__name__
cls_str = (' (%s not loaded)' %
self._expected_override_name)
raise SkipTest("Data function '%s' not found in '%s'%s" % (
data_fn_name, self._expected_override_name, using_str))
data_fn_name, self.__class__.__name__, cls_str))
else:
def data_fn(self, host, *args, **kwargs):
# call the corresponding 'actual' method