couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject [2/6] couchdb commit: updated refs/heads/1843-feature-bigcouch-multi-repo to 3069c01
Date Wed, 05 Feb 2014 14:35:02 GMT
Import JavaScript test runner changes

This is the basis for some temporary work to be able to run the
JavaScript test suite as during the merge transition.


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

Branch: refs/heads/1843-feature-bigcouch-multi-repo
Commit: 03ea534c0366164055560cc93d8fc32ceb27bf1f
Parents: a204d0a
Author: Paul J. Davis <paul.joseph.davis@gmail.com>
Authored: Tue Feb 4 21:47:09 2014 -0600
Committer: Paul J. Davis <paul.joseph.davis@gmail.com>
Committed: Wed Feb 5 08:34:52 2014 -0600

----------------------------------------------------------------------
 test/javascript/cli_runner.js |  85 +++++++-----------------
 test/javascript/run.tpl       | 133 ++++++++++++++++++++++++++-----------
 test/javascript/test_setup.js |  89 +++++++++++++++++++++++++
 3 files changed, 205 insertions(+), 102 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/03ea534c/test/javascript/cli_runner.js
----------------------------------------------------------------------
diff --git a/test/javascript/cli_runner.js b/test/javascript/cli_runner.js
index 5d82a51..e8ebd2e 100644
--- a/test/javascript/cli_runner.js
+++ b/test/javascript/cli_runner.js
@@ -9,78 +9,39 @@
 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 // License for the specific language governing permissions and limitations under
 // the License.
+//
 
-var console = {
-  log: function(arg) {
-    var msg = (arg.toString()).replace(/\n/g, "\n    ");
-    print(msg, true);
-  }
-};
+/*
+ * Futon test suite was designed to be able to run all tests populated into
+ * couchTests. Here we should only be loading one test, so we'll pop the first
+ * test off the list and run the test. If more than one item is loaded in the
+ * test object, return an error.
+ */
+function runTest() {
+  var count = 0;
+  var start = new Date().getTime();
 
-var fmtStack = function(stack) {
-  if(!stack) {
-    console.log("No stack information");
-    return;
-  }
-  console.log("Trace back (most recent call first):\n");
-  var re = new RegExp("(.*?)@([^:]*):(.*)$");
-  var lines = stack.split("\n");
-  for(var i = 0; i < lines.length; i++) {
-    var line = lines[i];
-    if(!line.length) continue;
-    var match = re.exec(line);
-    if(!match) continue
-    var source = match[1].substr(0, 70);
-    var file = match[2];
-    var lnum = match[3];
-    while(lnum.length < 3) lnum = " " + lnum;
-    console.log(" " + lnum + ": " + file);
-    console.log("      " + source);
+  for(var name in couchTests) {
+      count++;
   }
-}
-
 
-function T(arg1, arg2) {
-  if(!arg1) {
-    var result = (arg2 ? arg2 : arg1);
-    throw((result instanceof Error ? result : Error(result)));
+  if (count !== 1) {
+      console.log('Only one test per file is allowed.');
+      quit(1);
   }
-}
 
-function runTestConsole(num, name, func) {
-  CouchDB.reloadConfig();
-  var passed = false;
   try {
-    func();
-    passed = true;
-    print("ok " + num + " " + name);
+    // Add artificial wait for each test of 1 sec
+    while (new Date().getTime() < start + 1200);
+    couchTests[name]();
+    print('OK');
   } catch(e) {
-    print("not ok " + num + " " + name);
-    console.log("Reason: " + e.message);
+    console.log("FAIL\nReason: " + e.message);
     fmtStack(e.stack);
+    quit(1);
   }
-  return passed;
 }
 
-function runAllTestsConsole() {
-  var numTests = 0;
-  var numPassed = 0;
-  for(var t in couchTests) { numTests += 1; }
-  print("1.." + numTests);
-  var testId = 0;
-  for(var t in couchTests) {
-    testId += 1;
-    if(runTestConsole(testId, t, couchTests[t])) {
-      numPassed++;
-    }
-  }
-  if(numPassed != numTests) {
-    console.log("Test failures: " + (numTests - numPassed));
-    quit(1);
-  } else {
-    console.log("All tests passed");
-  }
-};
+waitForSuccess(CouchDB.isRunning, 'isRunning');
 
-waitForSuccess(CouchDB.getVersion);
-runAllTestsConsole();
+runTest();

http://git-wip-us.apache.org/repos/asf/couchdb/blob/03ea534c/test/javascript/run.tpl
----------------------------------------------------------------------
diff --git a/test/javascript/run.tpl b/test/javascript/run.tpl
index 141e9e8..75192da 100644
--- a/test/javascript/run.tpl
+++ b/test/javascript/run.tpl
@@ -17,7 +17,7 @@ BUILD_DIR=%abs_top_builddir%
 SCRIPT_DIR=$SRC_DIR/share/www/script
 JS_TEST_DIR=$SRC_DIR/test/javascript
 
-COUCHJS=%abs_top_builddir%/src/couch/priv/couchjs
+COUCHJS=%abs_top_builddir%/src/couchdb/priv/couchjs
 COUCH_URI_FILE=%localstaterundir%/couch.uri
 
 # make check-js calls us with MAKE=$(MAKE) so BSDish `gmake` invocations
@@ -27,59 +27,112 @@ if [ -z "$MAKE" ]; then
     MAKE=make
 fi
 
-if [ "$#" -eq 0 ];
-then
-    TEST_SRC="$SCRIPT_DIR/test/*.js"
-else
-    TEST_SRC="$1"
-    if [ ! -f $TEST_SRC ]; then
-        TEST_SRC="$SCRIPT_DIR/test/$1"
-        if [ ! -f $TEST_SRC ]; then
-            TEST_SRC="$SCRIPT_DIR/test/$1.js"
-            if [ ! -f $TEST_SRC ]; then
-                echo "file $1 does not exist"
-                exit 1
-            fi
-        fi
-    fi
-fi
+trap 'abort' EXIT INT
+
+start() {
+	./utils/run -b -r 0 -n \
+		-a $BUILD_DIR/etc/couchdb/default_dev.ini \
+		-a $SRC_DIR/test/random_port.ini \
+		-a $BUILD_DIR/etc/couchdb/local_dev.ini 1>/dev/null
+}
+
+stop() {
+    ./utils/run -d 1>/dev/null
+}
+
+restart() {
+    stop
+    start
+}
 
-# stop CouchDB on exit from various signals
 abort() {
     trap - 0
-    ./utils/run -d
+    stop
     exit 2
 }
 
+process_response() {
+    while read data
+    do
+        if [ $data = 'restart' ];
+        then
+            if [ -z $COUCHDB_NO_START ]; then
+                restart
+            fi
+        else
+            echo "$data"
+        fi
+    done
+}
+
+run() {
+    # start the tests
+    /bin/echo -n "$1 ... "
+    $COUCHJS -H -u $COUCH_URI_FILE \
+        $SCRIPT_DIR/json2.js \
+        $SCRIPT_DIR/sha1.js \
+        $SCRIPT_DIR/oauth.js \
+        $SCRIPT_DIR/couch.js \
+        $SCRIPT_DIR/replicator_db_inc.js \
+        $SCRIPT_DIR/couch_test_runner.js \
+        $JS_TEST_DIR/couch_http.js \
+        $JS_TEST_DIR/test_setup.js \
+        $1 \
+        $JS_TEST_DIR/cli_runner.js | process_response
+
+    if [ -z $RESULT ]; then
+        RESULT=$?
+    elif [ "$?" -eq 1 ]; then
+        RESULT=$?
+    fi
+
+}
+
+run_files() {
+    COUNTER=1
+    FILE_COUNT=$(ls -l $1 | wc -l)
+    FILE_COUNT=$(expr $FILE_COUNT + 0)
+    for TEST_SRC in $1
+    do
+        /bin/echo -n "$COUNTER/$FILE_COUNT "
+        COUNTER=$(expr $COUNTER + 1)
+        run $TEST_SRC
+    done
+}
+
 # start CouchDB
 if [ -z $COUCHDB_NO_START ]; then
     $MAKE dev
-    trap 'abort' EXIT INT
-	./utils/run -b -r 1 -n \
-		-a $BUILD_DIR/etc/couchdb/default_dev.ini \
-		-a $SRC_DIR/test/random_port.ini \
-		-a $BUILD_DIR/etc/couchdb/local_dev.ini
-	sleep 1 # give it a sec
+    start
 fi
 
-# start the tests
-$COUCHJS -H -u $COUCH_URI_FILE \
-	$SCRIPT_DIR/json2.js \
-	$SCRIPT_DIR/sha1.js \
-	$SCRIPT_DIR/oauth.js \
-	$SCRIPT_DIR/couch.js \
-	$SCRIPT_DIR/couch_test_runner.js \
-	$SCRIPT_DIR/couch_tests.js \
-	$TEST_SRC \
-	$JS_TEST_DIR/couch_http.js \
-	$JS_TEST_DIR/cli_runner.js
+echo "Running javascript tests ..."
 
-RESULT=$?
+if [ "$#" -eq 0 ];
+then
+    run_files "$SCRIPT_DIR/test/*.js"
+else
+    if [ -d $1 ]; then
+        run_files "$1/*.js"
+    else
+        TEST_SRC="$1"
+        if [ ! -f $TEST_SRC ]; then
+            TEST_SRC="$SCRIPT_DIR/test/$1"
+            if [ ! -f $TEST_SRC ]; then
+                TEST_SRC="$SCRIPT_DIR/test/$1.js"
+                if [ ! -f $TEST_SRC ]; then
+                    echo "file $1 does not exist"
+                    exit 1
+                fi
+            fi
+        fi
+    fi
+    run $TEST_SRC
+fi
 
 if [ -z $COUCHDB_NO_START ]; then
-    # stop CouchDB
-    ./utils/run -d
-    trap - 0
+    stop
 fi
 
+trap - 0
 exit $RESULT

http://git-wip-us.apache.org/repos/asf/couchdb/blob/03ea534c/test/javascript/test_setup.js
----------------------------------------------------------------------
diff --git a/test/javascript/test_setup.js b/test/javascript/test_setup.js
new file mode 100644
index 0000000..9347455
--- /dev/null
+++ b/test/javascript/test_setup.js
@@ -0,0 +1,89 @@
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// use this file except in compliance with the License. You may obtain a copy of
+// the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations under
+// the License.
+
+/*
+ * Add global couchTests object required for existing tests.
+ */
+var couchTests = {}; 
+
+var console = { 
+  log: function(arg) {
+    var msg = (arg.toString()).replace(/\n/g, "\n    ");
+    print(msg, true);
+  }
+};
+
+var fmtStack = function(stack) {
+  if(!stack) {
+    console.log("No stack information");
+    return;
+  }
+  console.log("Trace back (most recent call first):\n");
+  var re = new RegExp("(.*?)@([^:]*):(.*)$");
+  var lines = stack.split("\n");
+  for(var i = 0; i < lines.length; i++) {
+    var line = lines[i];
+    if(!line.length) continue;
+    var match = re.exec(line);
+    if(!match) continue
+    var match = re.exec(line);
+    if(!match) continue
+    var source = match[1].substr(0, 70);
+    var file = match[2];
+    var lnum = match[3];
+    while(lnum.length < 3) lnum = " " + lnum;
+    console.log(" " + lnum + ": " + file);
+    console.log("      " + source);
+  }
+} 
+
+function T(arg1, arg2) {
+  if(!arg1) {
+    var result = (arg2 ? arg2 : arg1);
+    throw((result instanceof Error ? result : Error(result)));
+  }
+} 
+
+function waitForSuccess(fun, tag) {
+  var start = new Date().getTime();
+  var complete = false;
+  
+  while (!complete) {
+    var now = new Date().getTime();
+    if (now > start + 5000) {
+      complete = true;
+      print('FAIL');
+      print(tag);
+      quit(1);
+    }
+    try {
+      while (new Date().getTime() < now + 500);
+      complete = fun();
+    } catch (e) {}
+  }
+}
+
+function restartServer() {
+  print('restart');
+  var start = new Date().getTime();
+  while (new Date().getTime() < start + 1000);
+  waitForSuccess(CouchDB.isRunning, 'restart');
+}
+
+/*
+ * If last_req is an object, we got something back. This might be an error, but
+ * CouchDB is up and running!
+ */
+CouchDB.isRunning = function() {
+  CouchDB.last_req = CouchDB.request("GET", "/");
+  return typeof CouchDB.last_req == 'object';
+};


Mime
View raw message