From ebd75eb1b98724b107f8fc010b6afa3ce45f42e8 Mon Sep 17 00:00:00 2001 From: Jiahui Li Date: Mon, 25 Nov 2024 23:20:57 -0600 Subject: [PATCH 1/3] Add `-F, --failfast` to stop mango tests early on failures --- Makefile | 2 +- Makefile.win | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 2310080149..a5aced9231 100644 --- a/Makefile +++ b/Makefile @@ -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)" .PHONY: weatherreport-test diff --git a/Makefile.win b/Makefile.win index c7d8bb000b..9d811bf6eb 100644 --- a/Makefile.win +++ b/Makefile.win @@ -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)" ################################################################################ From 2f6117e1d52f1cec26a8a27a20173a438fd55caa Mon Sep 17 00:00:00 2001 From: Jiahui Li Date: Fri, 22 Nov 2024 14:56:04 -0600 Subject: [PATCH 2/3] Run mango tests with custom db instead of recreating class db When running mango tests, sometimes get `org.apache.lucene.store.NoSuchDirectoryException` error. This is because each test in the same class used the same database name, and in the setUp function always delete and recreate it, which caused a race condition. Adding `setUp()` and `teadown()` to create/delete the db for each test should solve the issue. --- src/mango/test/mango.py | 49 +++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/src/mango/test/mango.py b/src/mango/test/mango.py index a23ba31471..066b5a3296 100644 --- a/src/mango/test/mango.py +++ b/src/mango/test/mango.py @@ -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) @@ -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): - 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]) @@ -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): From 0bef663d455664c0648eff69770fe5a657a6be57 Mon Sep 17 00:00:00 2001 From: Jiahui Li Date: Tue, 26 Nov 2024 09:01:57 -0600 Subject: [PATCH 3/3] Replace `recreate()` with `super().setUp(db_per_test=True)` --- src/mango/test/01-index-crud-test.py | 4 ++-- src/mango/test/12-use-correct-index-test.py | 2 +- src/mango/test/13-stable-update-test.py | 2 +- src/mango/test/14-json-pagination-test.py | 2 +- src/mango/test/16-index-selectors-test.py | 4 ++-- src/mango/test/17-multi-type-value-test.py | 4 ++-- src/mango/test/18-json-sort.py | 2 +- src/mango/test/19-find-conflicts.py | 2 +- src/mango/test/20-no-timeout-test.py | 2 +- src/mango/test/24-text-paginated-test.py | 2 +- src/mango/test/25-beginswith-test.py | 2 +- 11 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/mango/test/01-index-crud-test.py b/src/mango/test/01-index-crud-test.py index 4de7777999..8084a6bf76 100644 --- a/src/mango/test/01-index-crud-test.py +++ b/src/mango/test/01-index-crud-test.py @@ -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 = [ @@ -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 = [ diff --git a/src/mango/test/12-use-correct-index-test.py b/src/mango/test/12-use-correct-index-test.py index c21ad6c5e1..176835abf1 100644 --- a/src/mango/test/12-use-correct-index-test.py +++ b/src/mango/test/12-use-correct-index-test.py @@ -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): diff --git a/src/mango/test/13-stable-update-test.py b/src/mango/test/13-stable-update-test.py index 303f3fab1c..aebe622710 100644 --- a/src/mango/test/13-stable-update-test.py +++ b/src/mango/test/13-stable-update-test.py @@ -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( diff --git a/src/mango/test/14-json-pagination-test.py b/src/mango/test/14-json-pagination-test.py index 2d24301528..7b62f9c61d 100644 --- a/src/mango/test/14-json-pagination-test.py +++ b/src/mango/test/14-json-pagination-test.py @@ -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): diff --git a/src/mango/test/16-index-selectors-test.py b/src/mango/test/16-index-selectors-test.py index a30f601c48..d9cd058b3b 100644 --- a/src/mango/test/16-index-selectors-test.py +++ b/src/mango/test/16-index-selectors-test.py @@ -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): @@ -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): diff --git a/src/mango/test/17-multi-type-value-test.py b/src/mango/test/17-multi-type-value-test.py index 21e7afda42..28cf8d9540 100644 --- a/src/mango/test/17-multi-type-value-test.py +++ b/src/mango/test/17-multi-type-value-test.py @@ -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"]) @@ -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)) diff --git a/src/mango/test/18-json-sort.py b/src/mango/test/18-json-sort.py index 21ecfefdb9..ebc3b024e0 100644 --- a/src/mango/test/18-json-sort.py +++ b/src/mango/test/18-json-sort.py @@ -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): diff --git a/src/mango/test/19-find-conflicts.py b/src/mango/test/19-find-conflicts.py index bf865d6ea8..e0d2ef3928 100644 --- a/src/mango/test/19-find-conflicts.py +++ b/src/mango/test/19-find-conflicts.py @@ -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)) diff --git a/src/mango/test/20-no-timeout-test.py b/src/mango/test/20-no-timeout-test.py index cffdfc3350..051b9a56c6 100644 --- a/src/mango/test/20-no-timeout-test.py +++ b/src/mango/test/20-no-timeout-test.py @@ -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"}) diff --git a/src/mango/test/24-text-paginated-test.py b/src/mango/test/24-text-paginated-test.py index 84b3a2f4b2..bd420766c5 100644 --- a/src/mango/test/24-text-paginated-test.py +++ b/src/mango/test/24-text-paginated-test.py @@ -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={}, diff --git a/src/mango/test/25-beginswith-test.py b/src/mango/test/25-beginswith-test.py index df96560b4e..071cc9a1f3 100644 --- a/src/mango/test/25-beginswith-test.py +++ b/src/mango/test/25-beginswith-test.py @@ -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"])