2 # Copyright (C) The Arvados Authors. All rights reserved.
4 # SPDX-License-Identifier: AGPL-3.0
7 . `dirname "$(readlink -f "$0")"`/run-library.sh
9 read -rd "\000" helpmessage <<EOF
10 $(basename $0): Install and test Arvados components.
12 Exit non-zero if any tests fail.
15 $(basename $0) WORKSPACE=/path/to/arvados [options]
19 --skip FOO Do not test the FOO component.
20 --skip sanity Skip initial dev environment sanity checks.
21 --skip install Do not run any install steps. Just run tests.
22 You should provide GOPATH, GEMHOME, and VENVDIR options
23 from a previous invocation if you use this option.
24 --only FOO Do not test anything except the FOO component. If given
25 more than once, all specified test suites are run.
26 --temp DIR Install components and dependencies under DIR instead of
27 making a new temporary directory. Implies --leave-temp.
28 --leave-temp Do not remove GOPATH, virtualenv, and other temp dirs at exit.
29 Instead, show the path to give as --temp to reuse them in
30 subsequent invocations.
31 --repeat N Repeat each install/test step until it succeeds N times.
32 --retry Prompt to retry if an install or test suite fails.
33 --only-install Run specific install step. If given more than once,
34 all but the last are ignored.
35 --short Skip (or scale down) some slow tests.
36 --interactive Set up, then prompt for test/install steps to perform.
37 WORKSPACE=path Arvados source tree to test.
38 CONFIGSRC=path Dir with config.yml file containing PostgreSQL section for use by tests.
39 services/api_test="TEST=test/functional/arvados/v1/collections_controller_test.rb"
40 Restrict apiserver tests to the given file
41 sdk/python_test="tests/test_api.py::ArvadosApiTest"
42 Restrict Python SDK tests to the given class
43 lib/dispatchcloud_test="-check.vv"
44 Show all log messages, even when tests pass (also works
45 with services/keepstore_test etc.)
47 Print more debug messages
48 envvar=value Set \$envvar to value. Primarily useful for WORKSPACE,
49 *_test, and other examples shown above.
51 Assuming "--skip install" is not given, all components are installed
52 into \$GOPATH, \$VENDIR, and \$GEMHOME before running any tests. Many
53 test suites depend on other components being installed, and installing
54 everything tends to be quicker than debugging dependencies.
56 As a special concession to the current CI server config, CONFIGSRC
57 defaults to $HOME/arvados-api-server if that directory exists.
59 More information and background:
61 https://dev.arvados.org/projects/arvados/wiki/Running_tests
72 lib/controller/federation
73 lib/controller/railsproxy
82 lib/dispatchcloud/container
83 lib/dispatchcloud/scheduler
84 lib/dispatchcloud/sshexecutor
85 lib/dispatchcloud/worker
90 services/dockercleaner
99 services/crunch-dispatch-local
100 services/crunch-dispatch-slurm
101 services/workbench2_units
102 services/workbench2_integration
107 sdk/ruby-google-api-client
124 tools/crunchstat-summary
125 tools/crunchstat-summary:py3
128 tools/keep-block-check
132 # First make sure to remove any ARVADOS_ variables from the calling
133 # environment that could interfere with the tests.
134 unset $(env | cut -d= -f1 | grep \^ARVADOS_)
136 # Reset other variables that could affect our [tests'] behavior by
145 export LANG=en_US.UTF-8
155 if [[ -z "$temp" ]]; then
156 # we did not even get as far as making a temp dir
158 elif [[ -z "$temp_preserve" ]]; then
159 # Go creates readonly dirs in the module cache, which cause
160 # "rm -rf" to fail unless we chmod first.
164 echo "Leaving behind temp dirs in $temp"
170 echo >&2 "Fatal: $* (encountered in ${FUNCNAME[1]} at ${BASH_SOURCE[1]} line ${BASH_LINENO[0]})"
177 rotate_logfile "$WORKSPACE/services/api/log/" "test.log"
184 [[ -n "${skip[sanity]}" ]] && return 0
185 ( [[ -n "$WORKSPACE" ]] && [[ -d "$WORKSPACE/services" ]] ) \
186 || fatal "WORKSPACE environment variable not set to a source directory (see: $0 --help)"
187 [[ -z "$CONFIGSRC" ]] || [[ -s "$CONFIGSRC/config.yml" ]] \
188 || fatal "CONFIGSRC is $CONFIGSRC but '$CONFIGSRC/config.yml' is empty or not found (see: $0 --help)"
189 echo Checking dependencies:
190 echo "locale: ${LANG}"
191 [[ "$(locale charmap)" = "UTF-8" ]] \
192 || fatal "Locale '${LANG}' is broken/missing. Try: echo ${LANG} | sudo tee -a /etc/locale.gen && sudo locale-gen"
195 || fatal "No ruby. Install >=2.7 from package or source"
198 || fatal "No go binary. See http://golang.org/doc/install"
199 [[ $(go version) =~ go1.([0-9]+) ]] && [[ ${BASH_REMATCH[1]} -ge 12 ]] \
200 || fatal "Go >= 1.12 required. See http://golang.org/doc/install"
202 gcc --version | egrep ^gcc \
203 || fatal "No gcc. Try: apt-get install build-essential"
205 find /usr/include -path '*fuse/fuse.h' | egrep --max-count=1 . \
206 || fatal "No fuse/fuse.h. Try: apt-get install libfuse-dev"
208 find /usr/include -path '*gnutls/gnutls.h' | egrep --max-count=1 . \
209 || fatal "No gnutls/gnutls.h. Try: apt-get install libgnutls28-dev"
210 echo -n 'virtualenv: '
211 python3 -m venv --help | grep -q '^usage: venv ' \
212 && echo "venv module found" \
213 || fatal "No virtualenv. Try: apt-get install python3-venv"
214 echo -n 'Python3 pyconfig.h: '
215 find /usr/include -path '*/python3*/pyconfig.h' | egrep --max-count=1 . \
216 || fatal "No Python3 pyconfig.h. Try: apt-get install python3-dev"
218 || fatal "No netstat. Try: apt-get install net-tools"
220 PATH="$PATH:/sbin:/usr/sbin:/usr/local/sbin" nginx -v \
221 || fatal "No nginx. Try: apt-get install nginx"
224 || fatal "No npm. Try: wget -O- https://nodejs.org/dist/v12.22.12/node-v12.22.12-linux-x64.tar.xz | sudo tar -C /usr/local -xJf - && sudo ln -s ../node-v12.22.12-linux-x64/bin/{node,npm} /usr/local/bin/"
226 cadaver --version | grep -w cadaver \
227 || fatal "No cadaver. Try: apt-get install cadaver"
228 echo -n 'libattr1 xattr.h: '
229 find /usr/include -path '*/attr/xattr.h' | egrep --max-count=1 . \
230 || fatal "No libattr1 xattr.h. Try: apt-get install libattr1-dev"
231 echo -n 'libcurl curl.h: '
232 find /usr/include -path '*/curl/curl.h' | egrep --max-count=1 . \
233 || fatal "No libcurl curl.h. Try: apt-get install libcurl4-gnutls-dev"
234 echo -n 'libpq libpq-fe.h: '
235 find /usr/include -path '*/postgresql/libpq-fe.h' | egrep --max-count=1 . \
236 || fatal "No libpq libpq-fe.h. Try: apt-get install libpq-dev"
237 echo -n 'libpam pam_appl.h: '
238 find /usr/include -path '*/security/pam_appl.h' | egrep --max-count=1 . \
239 || fatal "No libpam pam_appl.h. Try: apt-get install libpam0g-dev"
240 echo -n 'postgresql: '
241 psql --version || fatal "No postgresql. Try: apt-get install postgresql postgresql-client-common"
243 which Xvfb || fatal "No xvfb. Try: apt-get install xvfb"
245 dot -V || fatal "No graphviz. Try: apt-get install graphviz"
246 echo -n 'singularity: '
247 singularity --version || fatal "No singularity. Try: arvados-server install"
248 echo -n 'docker client: '
249 docker --version || echo "No docker client. Try: arvados-server install"
250 echo -n 'docker server: '
251 docker info --format='{{.ServerVersion}}' || echo "No docker server. Try: arvados-server install"
253 if [[ "$NEED_SDK_R" = true ]]; then
256 which Rscript || fatal "No Rscript. Try: apt-get install r-base"
258 Rscript -e "library('testthat')" || fatal "No testthat. Try: apt-get install r-cran-testthat"
259 # needed for roxygen2, needed for devtools, needed for R sdk
260 pkg-config --exists libxml-2.0 || fatal "No libxml2. Try: apt-get install libxml2-dev"
261 # needed for pkgdown, builds R SDK doc pages
262 which pandoc || fatal "No pandoc. Try: apt-get install pandoc"
264 echo 'procs with /dev/fuse open:'
265 find /proc/*/fd -lname /dev/fuse 2>/dev/null | cut -d/ -f3 | xargs --no-run-if-empty ps -lywww
266 echo 'grep fuse /proc/self/mountinfo:'
267 grep fuse /proc/self/mountinfo
271 # i.e. rotate_logfile "$WORKSPACE/services/api/log/" "test.log"
272 # $BUILD_NUMBER is set by Jenkins if this script is being called as part of a Jenkins run
273 if [[ -f "$1/$2" ]]; then
274 THEDATE=`date +%Y%m%d%H%M%S`
275 mv "$1/$2" "$1/$THEDATE-$BUILD_NUMBER-$2"
276 gzip "$1/$THEDATE-$BUILD_NUMBER-$2"
290 echo >&2 "$helpmessage"
298 only[$1]=1; skip[$1]=""; shift
310 only_install="$1"; shift
320 repeat=$((${1}+0)); shift
326 suite="${arg%%_test=*}"
328 testargs["$suite"]="$args"
331 eval export $(echo $arg | cut -d= -f1)=\"$(echo $arg | cut -d= -f2-)\"
334 echo >&2 "$0: Unrecognized option: '$arg'. Try: $0 --help"
340 # R SDK installation is very slow (~360s in a clean environment) and only
341 # required when testing it. Skip that step if it is not needed.
344 if [[ ${#only[@]} -ne 0 ]] &&
345 [[ -z "${only['sdk/R']}" && -z "${only['doc']}" ]]; then
349 if [[ ${skip["sdk/R"]} == 1 && ${skip["doc"]} == 1 ]]; then
353 if [[ $NEED_SDK_R == false ]]; then
354 echo "R SDK not needed, it will not be installed."
359 pid="$(cat "$WORKSPACE/tmp/${svc}.pid")"
360 if [[ -z "$pid" ]] || ! kill -0 "$pid"; then
361 tail $WORKSPACE/tmp/${1}*.log
362 echo "${svc} pid ${pid} not running"
365 echo "${svc} pid ${pid} ok"
370 base=$("${VENV3DIR}/bin/python3" -c "import yaml; print(list(yaml.safe_load(open('$ARVADOS_CONFIG','r'))['Clusters']['zzzzz']['Services']['$1']['InternalURLs'].keys())[0])")
371 url="$base/_health/ping"
372 if ! curl -Ss -H "Authorization: Bearer e687950a23c3a9bceec28c6223a06c79" "${url}" | tee -a /dev/stderr | grep '"OK"'; then
378 checkdiscoverydoc() {
379 dd="https://${1}/discovery/v1/apis/arvados/v1/rest"
380 if ! (set -o pipefail; curl -fsk "$dd" | grep -q ^{ ); then
381 echo >&2 "ERROR: could not retrieve discovery doc from RailsAPI at $dd"
382 tail -v $WORKSPACE/tmp/railsapi.log
389 if [[ -n "$ARVADOS_TEST_API_HOST" ]]; then
392 . "$VENV3DIR/bin/activate"
393 echo 'Starting API, controller, keepproxy, keep-web, ws, and nginx ssl proxy...'
394 if [[ ! -d "$WORKSPACE/services/api/log" ]]; then
395 mkdir -p "$WORKSPACE/services/api/log"
397 # Remove empty api.pid file if it exists
398 if [[ -f "$WORKSPACE/tmp/api.pid" && ! -s "$WORKSPACE/tmp/api.pid" ]]; then
399 rm -f "$WORKSPACE/tmp/api.pid"
401 all_services_stopped=
405 && eval $(python3 sdk/python/tests/run_test_server.py start --auth admin) \
406 && export ARVADOS_TEST_API_HOST="$ARVADOS_API_HOST" \
407 && export ARVADOS_TEST_API_INSTALLED="$$" \
408 && checkpidfile api \
409 && checkdiscoverydoc $ARVADOS_API_HOST \
410 && eval $(python3 sdk/python/tests/run_test_server.py start_nginx) \
411 && checkpidfile nginx \
412 && python3 sdk/python/tests/run_test_server.py start_controller \
413 && checkpidfile controller \
414 && checkhealth Controller \
415 && checkdiscoverydoc $ARVADOS_API_HOST \
416 && python3 sdk/python/tests/run_test_server.py start_keep_proxy \
417 && checkpidfile keepproxy \
418 && python3 sdk/python/tests/run_test_server.py start_keep-web \
419 && checkpidfile keep-web \
420 && checkhealth WebDAV \
421 && python3 sdk/python/tests/run_test_server.py start_ws \
423 && export ARVADOS_TEST_PROXY_SERVICES=1 \
424 && (env | egrep ^ARVADOS) \
427 if [[ $fail != 0 ]]; then
428 unset ARVADOS_TEST_API_HOST
434 if [[ -n "$all_services_stopped" ]]; then
437 unset ARVADOS_TEST_API_HOST ARVADOS_TEST_PROXY_SERVICES
438 . "$VENV3DIR/bin/activate" || return
440 && python3 sdk/python/tests/run_test_server.py stop_nginx \
441 && python3 sdk/python/tests/run_test_server.py stop_ws \
442 && python3 sdk/python/tests/run_test_server.py stop_keep-web \
443 && python3 sdk/python/tests/run_test_server.py stop_keep_proxy \
444 && python3 sdk/python/tests/run_test_server.py stop_controller \
445 && python3 sdk/python/tests/run_test_server.py stop \
446 && all_services_stopped=1
452 if [[ -n "$ignore_sigint" ]]; then
453 echo >&2 "ignored SIGINT"
456 failures+=("($(basename $0) interrupted)")
461 setup_ruby_environment() {
462 # When our "bundle install"s need to install new gems to
463 # satisfy dependencies, we want them to go where "gem install
464 # --user-install" would put them. (However, if the caller has
465 # already set GEM_HOME, we assume that's where dependencies
466 # should be installed, and we should leave it alone.)
468 if [ -z "$GEM_HOME" ]; then
469 user_gempath="$(gem env gempath)"
470 export GEM_HOME="${user_gempath%%:*}"
472 PATH="$(gem env gemdir)/bin:$PATH"
474 # When we build and install our own gems, we install them in our
475 # $GEMHOME tmpdir, and we want them to be at the front of GEM_PATH and
476 # PATH so integration tests prefer them over other versions that
477 # happen to be installed in $user_gempath, system dirs, etc.
479 tmpdir_gem_home="$(env - PATH="$PATH" HOME="$GEMHOME" gem env gempath | cut -f1 -d:)"
480 PATH="$tmpdir_gem_home/bin:$PATH"
481 export GEM_PATH="$tmpdir_gem_home:$(gem env gempath)"
483 echo "Will install dependencies to $(gem env gemdir)"
484 echo "Will install bundler and arvados gems to $tmpdir_gem_home"
485 echo "Gem search path is GEM_PATH=$GEM_PATH"
486 gem install --user --no-document --conservative --version '~> 2.4.0' bundler \
487 || fatal 'install bundler'
491 GEM_HOME="$tmpdir_gem_home" GEM_PATH="$tmpdir_gem_home" "$@"
494 gem_uninstall_if_exists() {
495 if gem list "$1\$" | egrep '^\w'; then
496 gem uninstall --force --all --executables "$1"
501 local venvdest="$1"; shift
502 if ! [[ -e "$venvdest/bin/activate" ]] || ! [[ -e "$venvdest/bin/pip3" ]]; then
503 python3 -m venv "$@" "$venvdest" || fatal "virtualenv $venvdest failed"
504 elif [[ -n "$short" ]]; then
507 "$venvdest/bin/pip3" install --no-cache-dir 'setuptools>=68' 'pip>=20'
511 # If dependencies like ruby, go, etc. are installed in
512 # /var/lib/arvados -- presumably by "arvados-server install" --
513 # then we want to use those versions, instead of whatever happens
514 # to be installed in /usr.
515 PATH="/var/lib/arvados/bin:${PATH}"
518 echo "WORKSPACE=$WORKSPACE"
520 # Clean up .pyc files that may exist in the workspace
522 find -name '*.pyc' -delete
524 if [[ -z "$temp" ]]; then
528 # Set up temporary install dirs (unless existing dirs were supplied)
529 for tmpdir in VENV3DIR GOPATH GEMHOME R_LIBS
531 if [[ -z "${!tmpdir}" ]]; then
532 eval "$tmpdir"="$temp/$tmpdir"
534 if ! [[ -d "${!tmpdir}" ]]; then
535 mkdir "${!tmpdir}" || fatal "can't create ${!tmpdir} (does $temp exist?)"
539 rm -vf "${WORKSPACE}/tmp/*.log"
544 # Make sure our compiled binaries under test override anything
545 # else that might be in the environment.
546 export PATH=$GOPATH/bin:$PATH
548 # Jenkins config requires that glob tmp/*.log match something. Ensure
549 # that happens even if we don't end up running services that set up
551 mkdir -p "${WORKSPACE}/tmp/" || fatal "could not mkdir ${WORKSPACE}/tmp"
552 touch "${WORKSPACE}/tmp/controller.log" || fatal "could not touch ${WORKSPACE}/tmp/controller.log"
554 unset http_proxy https_proxy no_proxy
556 setup_ruby_environment
562 go mod download || fatal "Go deps failed"
563 which goimports >/dev/null || go install golang.org/x/tools/cmd/goimports@latest || fatal "Go setup failed"
565 setup_virtualenv "$VENV3DIR"
566 . "$VENV3DIR/bin/activate"
568 # parameterized and pytest are direct dependencies of Python tests.
569 # PyYAML is a test requirement used by run_test_server.py and needed for
570 # other, non-Python tests.
571 # pdoc is needed to build PySDK documentation.
572 # wheel modernizes the venv (as of early 2024) and makes it more closely
573 # match our package build environment.
574 # We run `setup.py build` first to generate _version.py.
575 pip install parameterized pytest PyYAML pdoc wheel \
576 && env -C "$WORKSPACE/sdk/python" python3 setup.py build \
577 && pip install "$WORKSPACE/sdk/python" \
578 || fatal "installing Python SDK and related dependencies failed"
586 if [[ "$remain" -gt 1 ]]; then
587 remain=$((${remain}-1))
588 title "(repeating ${remain} more times)"
592 elif [[ "$retry" == 1 ]]; then
593 read -p 'Try again? [Y/n] ' x
594 if [[ "$x" != "y" ]] && [[ "$x" != "" ]]
606 services/workbench2_units | services/workbench2_integration)
607 suite=services/workbench2
613 if [[ -n "${skip[$suite]}" || \
614 -n "${skip[$1]}" || \
615 (${#only[@]} -ne 0 && ${only[$suite]} -eq 0 && ${only[$1]} -eq 0) ]]; then
621 check_arvados_config "$1"
624 | arvados_version.py \
625 | cmd/arvados-package \
630 | lib/cloud/cloudtest \
633 | lib/dispatchcloud/sshexecutor \
634 | lib/dispatchcloud/worker \
636 | services/workbench2_integration \
637 | services/workbench2_units \
639 check_arvados_config "$1"
640 # don't care whether services are running
643 check_arvados_config "$1"
644 if ! start_services; then
645 checkexit 1 "$1 tests"
646 title "test $1 -- failed to start services"
651 retry do_test_once ${@}
655 version=${ARVADOS_VERSION:-$(git log -n1 --format=%H)-dev}
656 echo "-X git.arvados.org/arvados.git/lib/cmd.version=${version} -X main.version=${version} -s -w"
666 if which deactivate >/dev/null; then deactivate; fi
667 if ! . "$VENV3DIR/bin/activate"
670 elif [[ "$2" == "go" ]]
672 covername="coverage-$(echo "$1" | sed -e 's/\//_/g')"
673 coverflags=("-covermode=count" "-coverprofile=$WORKSPACE/tmp/.$covername.tmp")
675 if [[ "$1" == "cmd/arvados-package" ]]; then
676 testflags+=("-timeout" "20m")
678 # We do "go install" here to catch compilation errors
679 # before trying "go test". Otherwise, coverage-reporting
680 # mode makes Go show the wrong line numbers when reporting
681 # compilation errors.
682 go install -ldflags "$(go_ldflags)" "$WORKSPACE/$1" && \
683 cd "$WORKSPACE/$1" && \
684 if [[ -n "${testargs[$1]}" ]]
686 # "go test -check.vv giturl" doesn't work, but this
688 go test ${short:+-short} ${testflags[@]} ${testargs[$1]}
690 # The above form gets verbose even when testargs is
691 # empty, so use this form in such cases:
692 go test ${short:+-short} ${testflags[@]} ${coverflags[@]} "git.arvados.org/arvados.git/$1"
695 if [[ -f "$WORKSPACE/tmp/.$covername.tmp" ]]
697 go tool cover -html="$WORKSPACE/tmp/.$covername.tmp" -o "$WORKSPACE/tmp/$covername.html"
698 rm "$WORKSPACE/tmp/.$covername.tmp"
700 [[ $result = 0 ]] && gofmt -e -d *.go
701 elif [[ "$2" == "pip" ]]
704 cd "$WORKSPACE/$1" && pip install . && while :
706 tries=$((${tries}+1))
707 # $3 can name a path directory for us to use, including trailing
708 # slash; e.g., the bin/ subdirectory of a virtualenv.
709 if [[ -e "${3}activate" ]]; then
712 python3 -m pytest ${testargs[$1]}
714 # pytest uses exit code 2 to mean "test collection failed."
715 # See discussion in FUSE's IntegrationTest and MountTestBase.
716 if [[ ${tries} < 3 && ${result} == 2 ]]
718 printf '\n*****\n%s tests exited with code 2 -- retrying\n*****\n\n' "$1"
724 elif [[ "$2" != "" ]]
731 checkexit $result "$1 tests"
732 title "test $1 -- `timer`"
736 check_arvados_config() {
737 if [[ "$1" = "env" ]] ; then
740 if [[ -z "$ARVADOS_CONFIG" ]] ; then
741 # Create config file. The run_test_server script requires PyYAML,
742 # so virtualenv needs to be active. Downstream steps like
743 # workbench install which require a valid config.yml.
744 if [[ ! -s "$VENV3DIR/bin/activate" ]] ; then
747 . "$VENV3DIR/bin/activate"
749 eval $(python3 sdk/python/tests/run_test_server.py setup_config)
755 if [[ -n ${skip["install_$1"]} || -n "${skip[install]}" || ( -n "${only_install}" && "${only_install}" != "${1}" && "${only_install}" != "${2}" ) ]]; then
758 check_arvados_config "$1"
759 retry do_install_once ${@}
767 if which deactivate >/dev/null; then deactivate; fi
768 if [[ "$1" != "env" ]] && ! . "$VENV3DIR/bin/activate"; then
770 elif [[ "$2" == "go" ]]
772 go install -ldflags "$(go_ldflags)" "$WORKSPACE/$1"
773 elif [[ "$2" == "pip" ]]
775 # $3 can name a path directory for us to use, including trailing
776 # slash; e.g., the bin/ subdirectory of a virtualenv.
778 # Need to change to a different directory after creating
779 # the source dist package to avoid a pip bug.
780 # see https://arvados.org/issues/5766 for details.
782 # Also need to install twice, because if it believes the package is
783 # already installed, pip it won't install it. So the first "pip
784 # install" ensures that the dependencies are met, the second "pip
785 # install" ensures that we've actually installed the local package
788 && "${3}python3" setup.py sdist rotate --keep=1 --match .tar.gz \
790 && "${3}pip3" install --no-cache-dir "$WORKSPACE/$1/dist"/*.tar.gz \
791 && "${3}pip3" install --no-cache-dir --no-deps --ignore-installed "$WORKSPACE/$1/dist"/*.tar.gz
792 elif [[ "$2" != "" ]]
799 checkexit $result "$1 install"
800 title "install $1 -- `timer`"
804 bundle_install_trylocal() {
807 echo "(Running bundle install --local. 'could not find package' messages are OK.)"
808 if ! bundle install --local --no-deployment; then
809 echo "(Running bundle install again, without --local.)"
810 bundle install --no-deployment
817 cd "$WORKSPACE/doc" \
818 && bundle_install_trylocal \
825 with_test_gemset gem_uninstall_if_exists "$gemname" \
826 && cd "$WORKSPACE/$srcpath" \
827 && bundle_install_trylocal \
828 && gem build "$gemname.gemspec" \
829 && with_test_gemset gem install --no-document $(ls -t "$gemname"-*.gem|head -n1)
833 install_gem arvados sdk/ruby
836 install_sdk/ruby-google-api-client() {
837 install_gem arvados-google-api-client sdk/ruby-google-api-client
841 if [[ "$NEED_SDK_R" = true ]]; then
842 cd "$WORKSPACE/sdk/R" \
843 && Rscript --vanilla install_deps.R
848 install_gem arvados-cli sdk/cli
851 install_services/login-sync() {
852 install_gem arvados-google-api-client sdk/ruby-google-api-client
853 install_gem arvados sdk/ruby
854 install_gem arvados-login-sync services/login-sync
857 install_services/api() {
859 check_arvados_config "services/api"
860 cd "$WORKSPACE/services/api" \
861 && RAILS_ENV=test bundle_install_trylocal \
864 rm -f config/environments/test.rb
865 cp config/environments/test.rb.example config/environments/test.rb
867 # Clear out any lingering postgresql connections to the test
868 # database, so that we can drop it. This assumes the current user
869 # is a postgresql superuser.
870 cd "$WORKSPACE/services/api" \
871 && test_database=$("${VENV3DIR}/bin/python3" -c "import yaml; print(yaml.safe_load(open('$ARVADOS_CONFIG','r'))['Clusters']['zzzzz']['PostgreSQL']['Connection']['dbname'])") \
872 && psql "$test_database" -c "SELECT pg_terminate_backend (pg_stat_activity.pid::int) FROM pg_stat_activity WHERE pg_stat_activity.datname = '$test_database';" 2>/dev/null
874 mkdir -p "$WORKSPACE/services/api/tmp/pids"
876 cert="$WORKSPACE/services/api/tmp/self-signed"
877 if [[ ! -e "$cert.pem" || "$(date -r "$cert.pem" +%s)" -lt 1512659226 ]]; then
879 dir="$WORKSPACE/services/api/tmp"
881 openssl req -newkey rsa:2048 -nodes -subj '/C=US/ST=State/L=City/CN=localhost' -out "$cert.csr" -keyout "$cert.key" </dev/null
882 openssl x509 -req -in "$cert.csr" -signkey "$cert.key" -out "$cert.pem" -days 3650 -extfile <(printf 'subjectAltName=DNS:localhost,DNS:::1,DNS:0.0.0.0,DNS:127.0.0.1,IP:::1,IP:0.0.0.0,IP:127.0.0.1')
888 cd "$WORKSPACE/services/api"
889 export RAILS_ENV=test
890 if bin/rails db:environment:set ; then
894 bin/rake db:fixtures:load
898 declare -a pythonstuff
900 # The ordering of sdk/python, tools/crunchstat-summary, and
901 # sdk/cwl here is significant. See
902 # https://dev.arvados.org/issues/19744#note-26
904 tools/crunchstat-summary:py3
906 services/dockercleaner:py3
911 gostuff=($(cd "$WORKSPACE" && git ls-files | grep '\.go$' | sed -e 's/\/[^\/]*$//' | sort -u))
913 install_services/workbench2() {
914 cd "$WORKSPACE/services/workbench2" \
915 && make yarn-install ARVADOS_DIRECTORY="${WORKSPACE}"
919 local arvados_api_host=pirca.arvadosapi.com && \
920 env -C "$WORKSPACE/doc" \
921 bundle exec rake linkchecker \
922 arvados_api_host="$arvados_api_host" \
923 arvados_workbench_host="https://workbench.$arvados_api_host" \
924 baseurl="file://$WORKSPACE/doc/.site/" \
929 cd "$WORKSPACE" || return 1
930 dirs=$(ls -d */ | egrep -v 'vendor|tmp')
931 [[ -z "$(gofmt -e -d $dirs | tee -a /dev/stderr)" ]]
932 go vet -composites=false ./...
935 test_arvados_version.py() {
938 while read -d "" fn; do
939 if [[ -z "$orig_fn" ]]; then
941 elif ! cmp "$orig_fn" "$fn"; then
942 fail_count=$(( $fail_count + 1 ))
943 printf "FAIL: %s and %s are not identical\n" "$orig_fn" "$fn"
945 done < <(git -C "$WORKSPACE" ls-files -z | grep -z '/arvados_version\.py$')
947 "") return 66 ;; # EX_NOINPUT
948 *) return "$fail_count" ;;
952 test_services/api() {
953 rm -f "$WORKSPACE/services/api/git-commit.version"
954 cd "$WORKSPACE/services/api" \
955 && eval env RAILS_ENV=test ${short:+RAILS_TEST_SHORT=1} bundle exec rake test TESTOPTS=\'-v -d\' ${testargs[services/api]}
959 cd "$WORKSPACE/sdk/ruby" \
960 && bundle exec rake test TESTOPTS=-v ${testargs[sdk/ruby]}
963 test_sdk/ruby-google-api-client() {
964 echo "*** note \`test sdk/ruby-google-api-client\` does not actually run any tests, see https://dev.arvados.org/issues/20993 ***"
969 if [[ "$NEED_SDK_R" = true ]]; then
970 cd "$WORKSPACE/sdk/R" \
971 && Rscript --vanilla run_test.R
976 cd "$WORKSPACE/sdk/cli" \
977 && mkdir -p /tmp/keep \
978 && KEEP_LOCAL_STORE=/tmp/keep bundle exec rake test TESTOPTS=-v ${testargs[sdk/cli]}
982 cd "$WORKSPACE/sdk/java-v2" && gradle test ${testargs[sdk/java-v2]}
985 test_services/login-sync() {
986 cd "$WORKSPACE/services/login-sync" \
987 && bundle exec rake test TESTOPTS=-v ${testargs[services/login-sync]}
990 test_services/workbench2_units() {
991 cd "$WORKSPACE/services/workbench2" && make unit-tests ARVADOS_DIRECTORY="${WORKSPACE}" WORKSPACE="$(pwd)" ${testargs[services/workbench2]}
994 test_services/workbench2_integration() {
996 FAIL_FAST_ENABLED=false
997 if [[ -n ${interactive} ]]; then
999 FAIL_FAST_ENABLED=true
1001 cd "$WORKSPACE/services/workbench2" && make integration-tests ARVADOS_DIRECTORY="${WORKSPACE}" \
1002 WORKSPACE="$(pwd)" \
1003 INTERACTIVE=$INTERACTIVE \
1004 CYPRESS_FAIL_FAST_ENABLED=$FAIL_FAST_ENABLED \
1005 ${testargs[services/workbench2]}
1009 # Install parts needed by test suites
1011 do_install cmd/arvados-server go
1012 do_install tools/crunchstat-summary pip "${VENV3DIR}/bin/"
1013 do_install sdk/ruby-google-api-client
1016 do_install services/api
1017 # lib/controller integration tests depend on arv-mount to run
1019 do_install services/fuse pip "${VENV3DIR}/bin/"
1020 do_install services/keepproxy go
1021 do_install services/keep-web go
1027 do_install sdk/ruby-google-api-client
1031 do_install services/login-sync
1032 for p in "${pythonstuff[@]}"
1035 if [[ -z ${skip[python3]} ]]; then
1036 do_install ${dir} pip "$VENV3DIR/bin/"
1039 for g in "${gostuff[@]}"
1043 do_install services/api
1044 do_install services/workbench2
1049 do_test services/api
1051 do_test arvados_version.py
1053 do_test sdk/ruby-google-api-client
1057 do_test services/login-sync
1059 for p in "${pythonstuff[@]}"
1062 if [[ -z ${skip[python3]} ]]; then
1063 do_test ${dir} pip "$VENV3DIR/bin/"
1067 for g in "${gostuff[@]}"
1071 do_test services/workbench2_units
1072 do_test services/workbench2_integration
1077 for g in "${gostuff[@]}"
1083 help_interactive() {
1084 echo "== Interactive commands:"
1085 echo "TARGET (short for 'test DIR')"
1087 echo "10 test TARGET (run test 10 times)"
1088 echo "test TARGET:py3 (test with python3)"
1089 echo "test TARGET -check.vv (pass arguments to test)"
1090 echo "install TARGET"
1091 echo "install env (go/python libs)"
1092 echo "install deps (go/python libs + arvados components needed for integration tests)"
1093 echo "reset (...services used by integration tests)"
1095 echo "== Test targets:"
1096 echo "${!testfuncargs[@]}" | tr ' ' '\n' | sort | column
1101 declare -A testfuncargs=()
1102 for g in "${gostuff[@]}"; do
1103 testfuncargs[$g]="$g go"
1105 for p in "${pythonstuff[@]}"; do
1107 testfuncargs[$dir:py3]="$dir pip $VENV3DIR/bin/"
1110 testfuncargs["sdk/cli"]="sdk/cli"
1111 testfuncargs["sdk/R"]="sdk/R"
1112 testfuncargs["sdk/java-v2"]="sdk/java-v2"
1114 if [[ -z ${interactive} ]]; then
1121 if [[ -e "$VENV3DIR/bin/activate" ]]; then stop_services; fi
1123 if [[ "$TERM" = dumb ]]; then
1124 # assume emacs, or something, is offering a history buffer
1125 # and pre-populating the command will only cause trouble
1127 elif [[ ! -e "$VENV3DIR/bin/activate" ]]; then
1128 nextcmd="install deps"
1135 nextcmd="install deps"
1137 HISTFILE="$WORKSPACE/tmp/.history"
1140 while read -p 'What next? ' -e -i "$nextcmd" nextcmd; do
1141 history -s "$nextcmd"
1144 if [[ "${nextcmd}" =~ ^[0-9] ]]; then
1145 read count nextcmd <<<"${nextcmd}"
1147 read verb target opts <<<"${nextcmd}"
1148 target="${target%/}"
1149 target="${target/\/:/:}"
1166 argstarget=${target%:py3}
1167 testargs["$argstarget"]="${opts}"
1168 tt="${testfuncargs[${target}]}"
1170 while [ $count -gt 0 ]; do
1181 if [[ ${#successes[@]} -gt 0 || ${#failures[@]} -gt 0 ]]; then