You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ro...@apache.org on 2016/07/28 12:58:59 UTC

fauxton commit: updated refs/heads/master to 6a618eb

Repository: couchdb-fauxton
Updated Branches:
  refs/heads/master 8bb5be380 -> 6a618ebda


testsuite: autocheck if document/db appears after creation

make sure that at least one request is successful right after the
creation of the database.

PR: #754
PR-URL: https://github.com/apache/couchdb-fauxton/pull/754
Reviewed-By: garren smith <ga...@gmail.com>


Project: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/commit/6a618ebd
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/tree/6a618ebd
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/diff/6a618ebd

Branch: refs/heads/master
Commit: 6a618ebda054eb834fb0052c8261a091bc9bcd46
Parents: 8bb5be3
Author: Robert Kowalski <ro...@apache.org>
Authored: Wed Jul 27 17:56:49 2016 +0200
Committer: Robert Kowalski <ro...@apache.org>
Committed: Thu Jul 28 14:58:53 2016 +0200

----------------------------------------------------------------------
 .../tests/nightwatch/checkDatabaseTooltip.js    |  4 +-
 .../custom-commands/checkForDatabaseCreated.js  | 25 ++++--------
 .../custom-commands/checkForDocumentCreated.js  | 26 +++++--------
 .../custom-commands/createDatabase.js           | 21 +++++++---
 .../custom-commands/createDocument.js           | 20 ++++++++--
 test/nightwatch_tests/custom-commands/helper.js | 41 ++++++++++++++++++++
 6 files changed, 90 insertions(+), 47 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/6a618ebd/app/addons/databases/tests/nightwatch/checkDatabaseTooltip.js
----------------------------------------------------------------------
diff --git a/app/addons/databases/tests/nightwatch/checkDatabaseTooltip.js b/app/addons/databases/tests/nightwatch/checkDatabaseTooltip.js
index 2862fe7..7c54ee6 100644
--- a/app/addons/databases/tests/nightwatch/checkDatabaseTooltip.js
+++ b/app/addons/databases/tests/nightwatch/checkDatabaseTooltip.js
@@ -20,13 +20,13 @@ module.exports = {
         baseUrl = client.globals.test_settings.launch_url;
 
     client
-      .loginToGUI()
-
       // use nano to quickly set up a DB with a single doc
       .deleteDatabase(newDatabaseName)
       .createDatabase(newDatabaseName)
       .createDocument(newDocumentName, newDatabaseName)
 
+      .loginToGUI()
+
       // delete the document manually. This'll ensure the database page has at least one "!" icon
       .waitForElementPresent('#dashboard-content a[href="#/database/' + newDatabaseName + '/_all_docs"]', waitTime, false)
       .click('#dashboard-content a[href="#/database/' + newDatabaseName + '/_all_docs"]')

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/6a618ebd/test/nightwatch_tests/custom-commands/checkForDatabaseCreated.js
----------------------------------------------------------------------
diff --git a/test/nightwatch_tests/custom-commands/checkForDatabaseCreated.js b/test/nightwatch_tests/custom-commands/checkForDatabaseCreated.js
index a3ac324..1de4abd 100644
--- a/test/nightwatch_tests/custom-commands/checkForDatabaseCreated.js
+++ b/test/nightwatch_tests/custom-commands/checkForDatabaseCreated.js
@@ -15,6 +15,9 @@ var util = require('util'),
     helpers = require('../helpers/helpers.js'),
     request = require('request');
 
+const commandHelper = require('./helper.js');
+const checkForDatabaseCreated = commandHelper.checkForDatabaseCreated;
+
 function CheckForDatabaseCreated () {
   events.EventEmitter.call(this);
 }
@@ -23,29 +26,15 @@ function CheckForDatabaseCreated () {
 util.inherits(CheckForDatabaseCreated, events.EventEmitter);
 
 CheckForDatabaseCreated.prototype.command = function (databaseName, timeout) {
-  var couchUrl = this.client.options.db_url;
+  const couchUrl = this.client.options.db_url;
 
   if (!timeout) {
     timeout = helpers.maxWaitTime;
   }
 
-  var timeOutId = setTimeout(function () {
-    throw new Error('timeout waiting for db to appear');
-  }, timeout);
-
-  var intervalId = setInterval(function () {
-    request(couchUrl + '/_all_dbs', function (er, res, body) {
-      if (body) {
-        var reg = new RegExp('"' + databaseName + '"', 'g');
-        if (reg.test(body)) {
-          clearTimeout(timeOutId);
-          console.log('database created: ' + databaseName);
-          clearInterval(intervalId);
-          this.emit('complete');
-        }
-      }
-    }.bind(this));
-  }.bind(this), 1000);
+  checkForDatabaseCreated(couchUrl, databaseName, timeout, () => {
+    this.emit('complete');
+  });
 
   return this;
 };

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/6a618ebd/test/nightwatch_tests/custom-commands/checkForDocumentCreated.js
----------------------------------------------------------------------
diff --git a/test/nightwatch_tests/custom-commands/checkForDocumentCreated.js b/test/nightwatch_tests/custom-commands/checkForDocumentCreated.js
index 4b0e2e4..d6b156e 100644
--- a/test/nightwatch_tests/custom-commands/checkForDocumentCreated.js
+++ b/test/nightwatch_tests/custom-commands/checkForDocumentCreated.js
@@ -15,6 +15,9 @@ var util = require('util'),
     helpers = require('../helpers/helpers.js'),
     request = require('request');
 
+const commandHelper = require('./helper.js');
+const checkForDocumentCreated = commandHelper.checkForDocumentCreated;
+
 function CheckForDocumentCreated () {
   events.EventEmitter.call(this);
 }
@@ -23,7 +26,7 @@ function CheckForDocumentCreated () {
 util.inherits(CheckForDocumentCreated, events.EventEmitter);
 
 CheckForDocumentCreated.prototype.command = function (doc, timeout, db) {
-  var couchUrl = this.client.options.db_url;
+  const couchUrl = this.client.options.db_url;
 
   if (!db) {
     db = helpers.testDatabaseName;
@@ -33,22 +36,11 @@ CheckForDocumentCreated.prototype.command = function (doc, timeout, db) {
     timeout = helpers.maxWaitTime;
   }
 
-  var timeOutId = setTimeout(function () {
-    throw new Error('timeout waiting for doc to appear');
-  }, timeout);
-
-  var intervalId = setInterval(function () {
-    var url = [couchUrl, db, doc].join('/');
-
-    request(url, function (er, res, body) {
-      if (res && /^2..$/.test(res.statusCode)) {
-        clearTimeout(timeOutId);
-        console.log('doc created: ' + doc);
-        clearInterval(intervalId);
-        this.emit('complete');
-      }
-    }.bind(this));
-  }.bind(this), 1000);
+  const url = [couchUrl, db, doc].join('/');
+
+  checkForDocumentCreated(url, timeout, () => {
+    this.emit('complete');
+  });
 
   return this;
 };

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/6a618ebd/test/nightwatch_tests/custom-commands/createDatabase.js
----------------------------------------------------------------------
diff --git a/test/nightwatch_tests/custom-commands/createDatabase.js b/test/nightwatch_tests/custom-commands/createDatabase.js
index a7dcd6a..3eca7f2 100644
--- a/test/nightwatch_tests/custom-commands/createDatabase.js
+++ b/test/nightwatch_tests/custom-commands/createDatabase.js
@@ -14,6 +14,9 @@ var util = require('util'),
     events = require('events'),
     helpers = require('../helpers/helpers.js');
 
+const commandHelper = require('./helper.js');
+const checkForDatabaseCreated = commandHelper.checkForDatabaseCreated;
+
 function CreateDatabase () {
   events.EventEmitter.call(this);
 }
@@ -22,18 +25,24 @@ function CreateDatabase () {
 util.inherits(CreateDatabase, events.EventEmitter);
 
 CreateDatabase.prototype.command = function (databaseName) {
-  var that = this,
-      nano = helpers.getNanoInstance(this.client.options.db_url);
+  const nano = helpers.getNanoInstance(this.client.options.db_url);
+
 
-  nano.db.create(databaseName, function (err, body, header) {
+  nano.db.create(databaseName, (err, body, header) => {
     if (err) {
       console.log('Error in nano CreateDatabase Function: ' + databaseName, err.message);
-
     }
+
     console.log('nano - created a database: ' + databaseName);
-    // emit the complete event
-    that.emit('complete');
+
+    const timeout = helpers.maxWaitTime;
+    const couchUrl = this.client.options.db_url;
+
+    checkForDatabaseCreated(couchUrl, databaseName, timeout, () => {
+      this.emit('complete');
+    });
   });
+
   return this;
 };
 

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/6a618ebd/test/nightwatch_tests/custom-commands/createDocument.js
----------------------------------------------------------------------
diff --git a/test/nightwatch_tests/custom-commands/createDocument.js b/test/nightwatch_tests/custom-commands/createDocument.js
index 11082ba..13ae0cd 100644
--- a/test/nightwatch_tests/custom-commands/createDocument.js
+++ b/test/nightwatch_tests/custom-commands/createDocument.js
@@ -15,6 +15,9 @@ var util = require('util'),
     helpers = require('../helpers/helpers.js'),
     request = require('request');
 
+const commandHelper = require('./helper.js');
+const checkForDocumentCreated = commandHelper.checkForDocumentCreated;
+
 function CreateDocument () {
   events.EventEmitter.call(this);
 }
@@ -23,7 +26,7 @@ function CreateDocument () {
 util.inherits(CreateDocument, events.EventEmitter);
 
 CreateDocument.prototype.command = function (documentName, databaseName, docContents) {
-  var couchUrl = this.client.options.db_url;
+  const couchUrl = this.client.options.db_url;
 
   if (!docContents) {
     docContents = { dummyKey: 'testingValue' };
@@ -35,13 +38,22 @@ CreateDocument.prototype.command = function (documentName, databaseName, docCont
     uri: couchUrl + '/' + databaseName + '?w=3',
     body: docContents,
     json: true
-  }, function (err, res, body) {
+  }, (err, res, body) => {
     if (err) {
       console.log('Error in nano CreateDocument Function: ' + documentName + ', in database: ' + databaseName, err.message);
     }
     console.log('nano  - created a doc: ' + documentName + ', in database: ' + databaseName);
-    this.emit('complete');
-  }.bind(this));
+
+    if (!databaseName) {
+      databaseName = helpers.testDatabaseName;
+    }
+
+    const url = [couchUrl, databaseName, documentName].join('/');
+    checkForDocumentCreated(url, helpers.maxWaitTime, () => {
+      this.emit('complete');
+    });
+
+  });
 
   return this;
 };

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/6a618ebd/test/nightwatch_tests/custom-commands/helper.js
----------------------------------------------------------------------
diff --git a/test/nightwatch_tests/custom-commands/helper.js b/test/nightwatch_tests/custom-commands/helper.js
new file mode 100644
index 0000000..f558d14
--- /dev/null
+++ b/test/nightwatch_tests/custom-commands/helper.js
@@ -0,0 +1,41 @@
+const request = require('request');
+
+exports.checkForDocumentCreated = function checkForDocumentCreated (url, timeout, cb) {
+
+  const timeOutId = setTimeout(() => {
+    throw new Error('timeout waiting for doc to appear');
+  }, timeout);
+
+  const intervalId = setInterval(() => {
+
+    request(url, (er, res, body) => {
+      if (res && /^2..$/.test(res.statusCode)) {
+        clearTimeout(timeOutId);
+        console.log('check for doc created successful');
+        clearInterval(intervalId);
+
+        cb(null);
+      }
+    });
+  }, 1000);
+};
+
+exports.checkForDatabaseCreated = function checkForDatabaseCreated (couchUrl, databaseName, timeout, cb) {
+  const timeOutId = setTimeout(() => {
+    throw new Error('timeout waiting for db to appear');
+  }, timeout);
+
+  const intervalId = setInterval(() => {
+    request(couchUrl + '/_all_dbs', function (er, res, body) {
+      if (body) {
+        const reg = new RegExp('"' + databaseName + '"', 'g');
+        if (reg.test(body)) {
+          clearTimeout(timeOutId);
+          console.log('database created: ' + databaseName);
+          clearInterval(intervalId);
+          cb(null);
+        }
+      }
+    });
+  }, 1000);
+};