couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject [11/12] couchdb commit: updated refs/heads/1843-feature-bigcouch to 152a21a
Date Thu, 06 Feb 2014 22:12:25 GMT
Initial implementation of a new JS test runner

This fits into the dev/run format for allowing tests to run with an
available cluster. For now the JS tests only run against the backdoor
port.


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

Branch: refs/heads/1843-feature-bigcouch
Commit: 3e09a9acb8cee93378c7241fd0d3fadcf99258a5
Parents: b69f33f
Author: Paul J. Davis <paul.joseph.davis@gmail.com>
Authored: Thu Feb 6 16:10:32 2014 -0600
Committer: Paul J. Davis <paul.joseph.davis@gmail.com>
Committed: Thu Feb 6 16:10:32 2014 -0600

----------------------------------------------------------------------
 .gitignore                    |   1 -
 test/javascript/cli_runner.js |   5 +-
 test/javascript/run           | 103 +++++++++++++++++++++++++++++++++++++
 test/javascript/run.tpl       |  80 ----------------------------
 test/javascript/test_setup.js |   3 +-
 5 files changed, 107 insertions(+), 85 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/3e09a9ac/.gitignore
----------------------------------------------------------------------
diff --git a/.gitignore b/.gitignore
index 17fa92b..29b3732 100644
--- a/.gitignore
+++ b/.gitignore
@@ -20,4 +20,3 @@ src/couch/priv/couch_js/config.h
 src/couch/priv/couchjs
 src/couch/priv/couchspawnkillable
 
-test/javascript/run

http://git-wip-us.apache.org/repos/asf/couchdb/blob/3e09a9ac/test/javascript/cli_runner.js
----------------------------------------------------------------------
diff --git a/test/javascript/cli_runner.js b/test/javascript/cli_runner.js
index da2eed0..6688bae 100644
--- a/test/javascript/cli_runner.js
+++ b/test/javascript/cli_runner.js
@@ -34,10 +34,11 @@ function runTest() {
     // Add artificial wait for each test of 1 sec
     while (new Date().getTime() < start + 1200);
     couchTests[name]();
-    print('OK');
+    quit(0);
   } catch(e) {
-    console.log("FAIL\nReason: " + e.message);
+    console.log("Error: " + e.message);
     fmtStack(e.stack);
+    quit(1)
   }
 }
 

http://git-wip-us.apache.org/repos/asf/couchdb/blob/3e09a9ac/test/javascript/run
----------------------------------------------------------------------
diff --git a/test/javascript/run b/test/javascript/run
new file mode 100755
index 0000000..8b754fb
--- /dev/null
+++ b/test/javascript/run
@@ -0,0 +1,103 @@
+#!/usr/bin/env python
+#
+# 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.
+
+import atexit
+import contextlib as ctx
+import glob
+import optparse as op
+import os
+import re
+import select
+import subprocess as sp
+import sys
+import time
+import urllib
+
+
+USAGE = "%prog [options] [command to run...]"
+TEST_PATH = os.path.dirname(os.path.abspath(__file__))
+ROOT_PATH = os.path.dirname(os.path.dirname(TEST_PATH))
+N = 3
+
+COUCHJS = "src/couch/priv/couchjs"
+
+SCRIPTS = """
+    share/www/script/json2.js
+    share/www/script/sha1.js
+    share/www/script/oauth.js
+    share/www/script/couch.js
+    share/www/script/couch_test_runner.js
+    test/javascript/couch_http.js
+    test/javascript/test_setup.js
+""".split()
+
+RUNNER = "test/javascript/cli_runner.js"
+
+
+def run_couchjs(test):
+    sys.stderr.write(test + " ... ")
+    sys.stderr.flush()
+    cmd = [COUCHJS, "-H"] + SCRIPTS + [test, RUNNER]
+    p = sp.Popen(
+            cmd,
+            stdin = sp.PIPE,
+            stdout = sp.PIPE,
+            stderr = sys.stderr
+        )
+    for line in p.stdout:
+        if line.strip() == "restart":
+            print "restart_nodes()"
+        else:
+            sys.stderr.write(line)
+    p.wait()
+    if p.returncode == 0:
+        sys.stderr.write("OK" + os.linesep)
+    else:
+        sys.stderr.write("FAIL" + os.linesep)
+    sys.stderr.flush()
+
+
+def options():
+    return []
+
+
+def main():
+    parser = op.OptionParser(usage=USAGE, option_list=options())
+    opts, args = parser.parse_args()
+
+    tests = []
+    if not len(args):
+        args = ["share/www/script/test"]
+    for name in args:
+        if os.path.isdir(name):
+            tests.extend(glob.glob(os.path.join(name, "*.js")))
+        elif os.path.isfile(name):
+            tests.append(name)
+        else:
+            name = os.path.join("share/www/script/test", name)
+            if os.path.isfile(name):
+                tests.append(name)
+            elif os.path.isfile(name + ".js"):
+                tests.append(name + ".js")
+
+    for test in tests:
+        run_couchjs(test)
+
+
+
+if __name__ == "__main__":
+    try:
+        main()
+    except KeyboardInterrupt:
+        pass

http://git-wip-us.apache.org/repos/asf/couchdb/blob/3e09a9ac/test/javascript/run.tpl
----------------------------------------------------------------------
diff --git a/test/javascript/run.tpl b/test/javascript/run.tpl
deleted file mode 100644
index c0fd693..0000000
--- a/test/javascript/run.tpl
+++ /dev/null
@@ -1,80 +0,0 @@
-#!/bin/sh -e
-
-# 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.
-
-SRC_DIR=%rootdir%
-BUILD_DIR=%rootdir%
-SCRIPT_DIR=$SRC_DIR/share/www/script
-JS_TEST_DIR=$SRC_DIR/test/javascript
-COUCHJS=%rootdir%/src/couch/priv/couchjs
-
-
-run() {
-    # start the tests
-    /bin/echo -n "$1 ... "
-    $COUCHJS -H \
-        $SCRIPT_DIR/json2.js \
-        $SCRIPT_DIR/sha1.js \
-        $SCRIPT_DIR/oauth.js \
-        $SCRIPT_DIR/couch.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
-
-    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
-}
-
-echo "Running javascript tests ..."
-
-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
-
-exit $RESULT

http://git-wip-us.apache.org/repos/asf/couchdb/blob/3e09a9ac/test/javascript/test_setup.js
----------------------------------------------------------------------
diff --git a/test/javascript/test_setup.js b/test/javascript/test_setup.js
index 9347455..aaf0562 100644
--- a/test/javascript/test_setup.js
+++ b/test/javascript/test_setup.js
@@ -61,8 +61,7 @@ function waitForSuccess(fun, tag) {
     var now = new Date().getTime();
     if (now > start + 5000) {
       complete = true;
-      print('FAIL');
-      print(tag);
+      print('FAIL ' + tag);
       quit(1);
     }
     try {


Mime
View raw message