Skip to content

Commit

Permalink
[bug 711191] Fix elasticsearch timeout problem
Browse files Browse the repository at this point in the history
If elasticsearch (the process) isn't available, then the ESTestCases set
settings.ES_LIVE_INDEXING to True, then go to do some indexing stuff and
throw an exception.  Since that happens in setUp of ESTestCase, that means
that tearDown never gets called and therefore teardown_indexes never gets
called and settings.ES_LIVE_INDEXING never gets set back to False and
then a whole bunch of tests run with incremental indexing on.  Gah!

This is a mediocre fix where we change the order of setup_indexes so
we only set settings.ES_LIVE_INDEXING to True if indexing works.  The
better fix is to mock the setting in the specific tests so we don't
end up in this situation.
  • Loading branch information
willkg committed Dec 15, 2011
1 parent bde906f commit 75976bc
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions apps/sumo/tests/__init__.py
Expand Up @@ -79,8 +79,6 @@ def setup_indexes(self):
if getattr(settings, 'ES_HOSTS', None) is None:
raise SkipTest

settings.ES_LIVE_INDEXING = True

# Delete test indexes if they exist.
es = get_es()
for index in settings.ES_INDEXES.values():
Expand All @@ -90,6 +88,18 @@ def setup_indexes(self):

es_reindex()

# TODO: This is kind of bad. If setup_indexes gets called in
# a setUp and that setUp at some point throws an exception, we
# could end up in a situation where setUp throws an exception,
# so tearDown doesn't get called and we never set
# ES_LIVE_INDEXING to False and thus ES_LIVE_INDEXING is True
# for a bunch of tests it shouldn't be true for.
#
# For settings like this, it's better to mock it in the class
# because the mock will set it back regardless of whether the
# test fails.
settings.ES_LIVE_INDEXING = True

def teardown_indexes(self):
es = get_es()
for index in settings.ES_INDEXES.values():
Expand Down

0 comments on commit 75976bc

Please sign in to comment.