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 mango tests using custom db name #5341

Merged
merged 3 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ mango-test: devclean all
--admin=adm:pass \
--no-eval "\
COUCH_USER=adm COUCH_PASS=pass \
src/mango/.venv/bin/nose2 -s src/mango/test -c src/mango/unittest.cfg $(MANGO_TEST_OPTS)"
src/mango/.venv/bin/nose2 -F -s src/mango/test -c src/mango/unittest.cfg $(MANGO_TEST_OPTS)"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does -F buy for us? The Mango tests are quick to run, and sometimes perhaps it is good to see if there are other errors besides the one that failed the whole run.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While working on this, I even changed unittest.cfg to run 16-index-selectors-test.py only. Because I keep getting 500 errors due to this test file. Different combinations of test cases will result in the same failure message but fail on different test cases. 0.85 sec vs 50 sec to run the entire test suite.

-F, --failfast allows us to identify the issue quickly, speed up the feedback loop, and make debugging easier.



.PHONY: weatherreport-test
Expand Down
2 changes: 1 addition & 1 deletion Makefile.win
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ mango-test: devclean all
--admin=adm:pass \
"\
env COUCH_USER=adm COUCH_PASS=pass \
src\mango\.venv\Scripts\nose2 -s src\mango\test -c src\mango\unittest.cfg $(MANGO_TEST_OPTS)"
src\mango\.venv\Scripts\nose2 -F -s src\mango\test -c src\mango\unittest.cfg $(MANGO_TEST_OPTS)"


################################################################################
Expand Down
4 changes: 2 additions & 2 deletions src/mango/test/01-index-crud-test.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

class IndexCrudTests(mango.DbPerClass):
def setUp(self):
self.db.recreate()
super().setUp(db_per_test=True)

def test_bad_fields(self):
bad_fields = [
Expand Down Expand Up @@ -352,7 +352,7 @@ def test_out_of_sync(self):
@unittest.skipUnless(mango.has_text_service(), "requires text service")
class IndexCrudTextTests(mango.DbPerClass):
def setUp(self):
self.db.recreate()
super().setUp(db_per_test=True)

def test_create_text_idx(self):
fields = [
Expand Down
2 changes: 1 addition & 1 deletion src/mango/test/12-use-correct-index-test.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@

class ChooseCorrectIndexForDocs(mango.DbPerClass):
def setUp(self):
self.db.recreate()
super().setUp(db_per_test=True)
self.db.save_docs(copy.deepcopy(DOCS))

def test_choose_index_with_one_field_in_index(self):
Expand Down
2 changes: 1 addition & 1 deletion src/mango/test/13-stable-update-test.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

class SupportStableAndUpdate(mango.DbPerClass):
def setUp(self):
self.db.recreate()
super().setUp(db_per_test=True)
# Hack to prevent auto-indexer from foiling update=False test
# https://github.com/apache/couchdb/issues/2313
self.db.save_doc(
Expand Down
2 changes: 1 addition & 1 deletion src/mango/test/14-json-pagination-test.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

class PaginateJsonDocs(mango.DbPerClass):
def setUp(self):
self.db.recreate()
super().setUp(db_per_test=True)
self.db.save_docs(copy.deepcopy(DOCS))

def test_all_docs_paginate_to_end(self):
Expand Down
4 changes: 2 additions & 2 deletions src/mango/test/16-index-selectors-test.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@

class IndexSelectorJson(mango.DbPerClass):
def setUp(self):
self.db.recreate()
super().setUp(db_per_test=True)
self.db.save_docs(copy.deepcopy(DOCS))

def test_saves_partial_filter_selector_in_index(self):
Expand Down Expand Up @@ -189,7 +189,7 @@ def test_uses_partial_index_with_non_indexable_selector(self):
@unittest.skipUnless(mango.has_text_service(), "requires text service")
class IndexSelectorText(mango.DbPerClass):
def setUp(self):
self.db.recreate()
super().setUp(db_per_test=True)
self.db.save_docs(copy.deepcopy(DOCS))

def test_saves_partialfilterselector_in_index(self):
Expand Down
4 changes: 2 additions & 2 deletions src/mango/test/17-multi-type-value-test.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def test_can_query_with_age_and_name_range(self):

class MultiValueFieldJSONTests(mango.DbPerClass, MultiValueFieldTests):
def setUp(self):
self.db.recreate()
super().setUp(db_per_test=True)
self.db.save_docs(copy.deepcopy(DOCS))
self.db.create_index(["name"])
self.db.create_index(["age", "name"])
Expand All @@ -65,5 +65,5 @@ def setUp(self):

class MultiValueFieldAllDocsTests(mango.DbPerClass, MultiValueFieldTests):
def setUp(self):
self.db.recreate()
super().setUp(db_per_test=True)
self.db.save_docs(copy.deepcopy(DOCS))
2 changes: 1 addition & 1 deletion src/mango/test/18-json-sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

class JSONIndexSortOptimisations(mango.DbPerClass):
def setUp(self):
self.db.recreate()
super().setUp(db_per_test=True)
self.db.save_docs(copy.deepcopy(DOCS))

def test_works_for_basic_case(self):
Expand Down
2 changes: 1 addition & 1 deletion src/mango/test/19-find-conflicts.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

class ChooseCorrectIndexForDocs(mango.DbPerClass):
def setUp(self):
self.db.recreate()
super().setUp(db_per_test=True)
self.db.save_docs(copy.deepcopy(DOC))
self.db.save_docs_with_conflicts(copy.deepcopy(CONFLICT))

Expand Down
2 changes: 1 addition & 1 deletion src/mango/test/20-no-timeout-test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

class LongRunningMangoTest(mango.DbPerClass):
def setUp(self):
self.db.recreate()
super().setUp(db_per_test=True)
docs = []
for i in range(100000):
docs.append({"_id": str(i), "another": "field"})
Expand Down
2 changes: 1 addition & 1 deletion src/mango/test/24-text-paginated-test.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class PaginatedResultsTest(mango.DbPerClass):
UPDATES = 25

def setUp(self):
self.db.recreate()
super().setUp(db_per_test=True)
self.db.create_text_index(
analyzer="keyword",
default_field={},
Expand Down
2 changes: 1 addition & 1 deletion src/mango/test/25-beginswith-test.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def to_utf8_bytes(list):

class BeginsWithOperator(mango.DbPerClass):
def setUp(self):
self.db.recreate()
super().setUp(db_per_test=True)
self.db.save_docs(copy.deepcopy(DOCS))
self.db.create_index(["location"])
self.db.create_index(["name", "location"])
Expand Down
49 changes: 27 additions & 22 deletions src/mango/test/mango.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,7 @@ def join(self):


class Database(object):
def __init__(
self,
dbname,
):
def __init__(self, dbname):
self.dbname = dbname
self.sess = requests.session()
self.sess.auth = (COUCH_USER, COUCH_PASS)
Expand All @@ -107,24 +104,19 @@ def create(self, q=1, n=1, partitioned=False):

def delete(self):
r = self.sess.delete(self.url)
r.raise_for_status()

def recreate(self):
NUM_TRIES = 10

for k in range(NUM_TRIES):
Copy link
Contributor Author

@jiahuili430 jiahuili430 Nov 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried many times, k is only equal to 0 and 1, so I guess maybe we can revert them back.

r = self.sess.get(self.url)
if r.status_code == 200:
db_info = r.json()
docs = db_info["doc_count"] + db_info["doc_del_count"]
if docs == 0:
# db exists and it is empty -- exit condition is met
return
self.delete()
self.create()
time.sleep(k * 0.1)
raise Exception(
"Failed to recreate the database after {} tries".format(NUM_TRIES)
)
r = self.sess.get(self.url)
if r.status_code == 200:
db_info = r.json()
docs = db_info["doc_count"] + db_info["doc_del_count"]
if docs == 0:
# db is not in use, no need to recreate
return
self.delete()
self.create()
self.recreate()

def save_doc(self, doc):
self.save_docs([doc])
Expand Down Expand Up @@ -356,8 +348,21 @@ def tearDownClass(klass):
if clean_up_dbs():
klass.db.delete()

def setUp(self):
self.db = self.__class__.db
def setUp(self, db_per_test=False, partitioned=False):
if db_per_test:
self.db = Database(random_db_name())
self.db.create(q=1, n=1, partitioned=partitioned)
self.db_per_test = db_per_test
else:
self.db = self.__class__.db

def tearDown(self):
if (
hasattr(self, "db_per_test")
and self.__getattribute__("db_per_test")
and clean_up_dbs()
):
self.db.delete()


class UserDocsTests(DbPerClass):
Expand Down