diff options
author | Will Holley <willholley@gmail.com> | 2017-11-16 08:21:56 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-16 08:21:56 +0000 |
commit | 8b4e92ae240d82837a0dede78fe5c1f664486f1c (patch) | |
tree | 710a9d466b20d668039f897addee11d43d5fbaa6 | |
parent | ead77b26d559415e4bdd302ffae50027112567f4 (diff) | |
download | couchdb-8b4e92ae240d82837a0dede78fe5c1f664486f1c.tar.gz |
Improve Mango test suite performance (#995)
* Remove artificial delays from database and index create/delete.
* Wait for indexes to report as created/deleted during test setup.
* Skip unnecessary database delete/create cycles.
* Default to n=1 when creating test databases. We don't have
tests that explicitly test n=3 scenarios and the tests generally
run on a single-node harness. Defaulting to n=1 allows the test
behaviour to be consistent when run on multi-node clusters.
* Add delay on cluster setup for Mango tests to mitigate tests
running before async cluster setup completes.
-rw-r--r-- | src/mango/test/mango.py | 39 | ||||
-rwxr-xr-x | test/build/test-run-couch-for-mango.sh | 3 |
2 files changed, 34 insertions, 8 deletions
diff --git a/src/mango/test/mango.py b/src/mango/test/mango.py index 03cc67c52..560914b8c 100644 --- a/src/mango/test/mango.py +++ b/src/mango/test/mango.py @@ -81,10 +81,14 @@ class Database(object): r = self.sess.delete(self.url) def recreate(self): + r = self.sess.get(self.url) + db_info = r.json() + docs = db_info["doc_count"] + db_info["doc_del_count"] + if docs == 0: + # db never used - create unnecessary + return self.delete() - delay() self.create() - delay() def save_doc(self, doc): self.save_docs([doc]) @@ -126,11 +130,17 @@ class Database(object): body["index"]["partial_filter_selector"] = partial_filter_selector body = json.dumps(body) r = self.sess.post(self.path("_index"), data=body) - delay() r.raise_for_status() assert r.json()["id"] is not None assert r.json()["name"] is not None - return r.json()["result"] == "created" + + created = r.json()["result"] == "created" + if created: + # wait until the database reports the index as available + while len(self.get_index(r.json()["id"], r.json()["name"])) < 1: + delay(t=0.1) + + return created def create_text_index(self, analyzer=None, idx_type="text", partial_filter_selector=None, default_field=None, fields=None, @@ -157,7 +167,6 @@ class Database(object): body["ddoc"] = ddoc body = json.dumps(body) r = self.sess.post(self.path("_index"), data=body) - delay() r.raise_for_status() return r.json()["result"] == "created" @@ -169,13 +178,28 @@ class Database(object): r = self.sess.get(self.path("_index?"+limit+";"+skip)) r.raise_for_status() return r.json()["indexes"] + + def get_index(self, ddocid, name): + if ddocid is None: + return [i for i in self.list_indexes() if i["name"] == name] + + ddocid = ddocid.replace("%2F", "/") + if not ddocid.startswith("_design/"): + ddocid = "_design/" + ddocid + + if name is None: + return [i for i in self.list_indexes() if i["ddoc"] == ddocid] + else: + return [i for i in self.list_indexes() if i["ddoc"] == ddocid and i["name"] == name] def delete_index(self, ddocid, name, idx_type="json"): path = ["_index", ddocid, idx_type, name] r = self.sess.delete(self.path(path), params={"w": "3"}) - delay() r.raise_for_status() + while len(self.get_index(ddocid, name)) == 1: + delay(t=0.1) + def bulk_delete(self, docs): body = { "docids" : docs, @@ -183,7 +207,6 @@ class Database(object): } body = json.dumps(body) r = self.sess.post(self.path("_index/_bulk_delete"), data=body) - delay(n=10) return r.json() def find(self, selector, limit=25, skip=0, sort=None, fields=None, @@ -245,7 +268,7 @@ class DbPerClass(unittest.TestCase): @classmethod def setUpClass(klass): klass.db = Database(random_db_name()) - klass.db.create(q=1, n=3) + klass.db.create(q=1, n=1) def setUp(self): self.db = self.__class__.db diff --git a/test/build/test-run-couch-for-mango.sh b/test/build/test-run-couch-for-mango.sh index 0597a8fca..472b19bd0 100755 --- a/test/build/test-run-couch-for-mango.sh +++ b/test/build/test-run-couch-for-mango.sh @@ -24,6 +24,9 @@ while ( [ $COUCH_STARTED -ne 0 ] ); do fi done +# wait for cluster setup to complete +sleep 5 + cd src/mango/ nosetests |