Merge branch 'master' into sigint
[arvados-dev.git] / jenkins / run-tests.sh
index a0fefaaf57caf7883040f6e1a7312561f63adf49..713ffdab1109a85b6cf4daafb33f64c2cd077931 100755 (executable)
@@ -126,6 +126,16 @@ report_outcomes() {
     fi
 }
 
+exit_cleanly() {
+    trap - INT
+    rotate_logfile "$WORKSPACE/apps/workbench/log/" "test.log"
+    stop_api
+    rotate_logfile "$WORKSPACE/services/api/log/" "test.log"
+    report_outcomes
+    clear_temp
+    exit ${#failures}
+}
+
 sanity_checks() {
   # Make sure WORKSPACE is set
   if ! [[ -n "$WORKSPACE" ]]; then
@@ -165,7 +175,6 @@ sanity_checks() {
     echo >&2
     exit 1
   fi
-
 }
 
 rotate_logfile() {
@@ -221,6 +230,29 @@ do
     esac
 done
 
+start_api() {
+    echo 'Starting API server...'
+    cd "$WORKSPACE" \
+        && eval $(python sdk/python/tests/run_test_server.py start --auth admin) \
+        && export ARVADOS_TEST_API_HOST="$ARVADOS_API_HOST" \
+        && export ARVADOS_TEST_API_INSTALLED="$$" \
+        && (env | egrep ^ARVADOS)
+}
+
+stop_api() {
+    if [[ -n "$ARVADOS_TEST_API_HOST" ]]; then
+        unset ARVADOS_TEST_API_HOST
+        cd "$WORKSPACE" \
+            && python sdk/python/tests/run_test_server.py stop
+    fi
+}
+
+interrupt() {
+    failures+=("($(basename $0) interrupted)")
+    exit_cleanly
+}
+trap interrupt INT
+
 sanity_checks
 
 echo "WORKSPACE=$WORKSPACE"
@@ -334,7 +366,8 @@ then
 fi
 
 # Needed for run_test_server.py which is used by certain (non-Python) tests.
-pip install PyYAML || fatal "pip install PyYAML failed"
+echo "pip install -q PyYAML"
+pip install -q PyYAML || fatal "pip install PyYAML failed"
 
 checkexit() {
     if [[ "$?" != "0" ]]; then
@@ -390,7 +423,7 @@ do_install() {
         then
             cd "$WORKSPACE/$1" \
                 && python setup.py sdist rotate --keep=1 --match .tar.gz \
-                && pip install --upgrade dist/*.tar.gz
+                && pip install -q --upgrade dist/*.tar.gz
         elif [[ "$2" != "" ]]
         then
             "install_$2"
@@ -525,25 +558,11 @@ done
 
 install_workbench() {
     cd "$WORKSPACE/apps/workbench" \
+        && mkdir -p tmp/cache \
         && RAILS_ENV=test bundle_install_trylocal
 }
 do_install apps/workbench workbench
 
-start_api() {
-    echo 'Starting API server...'
-    cd "$WORKSPACE" \
-        && eval $(python sdk/python/tests/run_test_server.py start --auth admin) \
-        && export ARVADOS_TEST_API_HOST="$ARVADOS_API_HOST" \
-        && export ARVADOS_TEST_API_INSTALLED="$$" \
-        && (env | egrep ^ARVADOS)
-}
-
-stop_api() {
-    unset ARVADOS_TEST_API_HOST
-    cd "$WORKSPACE" \
-        && python sdk/python/tests/run_test_server.py stop
-}
-
 test_doclinkchecker() {
     (
         set -e
@@ -564,6 +583,13 @@ test_apiserver() {
 }
 do_test services/api apiserver
 
+# Shortcut for when we're only running apiserver tests. This saves a bit of time,
+# because we don't need to start up the api server for subsequent tests.
+if [ ! -z "$only" ] && [ "$only" == "services/api" ]; then
+  rotate_logfile "$WORKSPACE/services/api/log/" "test.log"
+  exit_cleanly
+fi
+
 start_api
 
 test_ruby_sdk() {
@@ -607,12 +633,4 @@ test_workbench_profile() {
 }
 do_test apps/workbench_profile workbench_profile
 
-rotate_logfile "$WORKSPACE/apps/workbench/log/" "test.log"
-
-stop_api
-rotate_logfile "$WORKSPACE/services/api/log/" "test.log"
-
-report_outcomes
-clear_temp
-
-exit ${#failures}
+exit_cleanly