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
98 services/crunch-dispatch-local
99 services/crunch-dispatch-slurm
100 services/workbench2_units
101 services/workbench2_integration
106 sdk/ruby-google-api-client
122 tools/crunchstat-summary
125 tools/keep-block-check
129 # First make sure to remove any ARVADOS_ variables from the calling
130 # environment that could interfere with the tests.
131 unset $(env | cut -d= -f1 | grep \^ARVADOS_)
133 # Reset other variables that could affect our [tests'] behavior by
141 export LANG=en_US.UTF-8
151 if [[ -z "$temp" ]]; then
152 # we did not even get as far as making a temp dir
154 elif [[ -z "$temp_preserve" ]]; then
155 # Go creates readonly dirs in the module cache, which cause
156 # "rm -rf" to fail unless we chmod first.
160 echo "Leaving behind temp dirs in $temp"
166 echo >&2 "Fatal: $* (encountered in ${FUNCNAME[1]} at ${BASH_SOURCE[1]} line ${BASH_LINENO[0]})"
173 rotate_logfile "$WORKSPACE/services/api/log/" "test.log"
180 [[ -n "${skip[sanity]}" ]] && return 0
181 ( [[ -n "$WORKSPACE" ]] && [[ -d "$WORKSPACE/services" ]] ) \
182 || fatal "WORKSPACE environment variable not set to a source directory (see: $0 --help)"
183 [[ -z "$CONFIGSRC" ]] || [[ -s "$CONFIGSRC/config.yml" ]] \
184 || fatal "CONFIGSRC is $CONFIGSRC but '$CONFIGSRC/config.yml' is empty or not found (see: $0 --help)"
185 echo Checking dependencies:
186 echo "locale: ${LANG}"
187 [[ "$(locale charmap)" = "UTF-8" ]] \
188 || fatal "Locale '${LANG}' is broken/missing. Try: echo ${LANG} | sudo tee -a /etc/locale.gen && sudo locale-gen"
191 || fatal "No ruby. Install >=2.7 from package or source"
194 || fatal "No go binary. See http://golang.org/doc/install"
195 [[ $(go version) =~ go1.([0-9]+) ]] && [[ ${BASH_REMATCH[1]} -ge 12 ]] \
196 || fatal "Go >= 1.12 required. See http://golang.org/doc/install"
198 gcc --version | egrep ^gcc \
199 || fatal "No gcc. Try: apt-get install build-essential"
201 find /usr/include -path '*fuse/fuse.h' | egrep --max-count=1 . \
202 || fatal "No fuse/fuse.h. Try: apt-get install libfuse-dev"
204 find /usr/include -path '*gnutls/gnutls.h' | egrep --max-count=1 . \
205 || fatal "No gnutls/gnutls.h. Try: apt-get install libgnutls28-dev"
206 echo -n 'virtualenv: '
207 python3 -m venv --help | grep -q '^usage: venv ' \
208 && echo "venv module found" \
209 || fatal "No virtualenv. Try: apt-get install python3-venv"
210 echo -n 'Python3 pyconfig.h: '
211 find /usr/include -path '*/python3*/pyconfig.h' | egrep --max-count=1 . \
212 || fatal "No Python3 pyconfig.h. Try: apt-get install python3-dev"
214 || fatal "No netstat. Try: apt-get install net-tools"
216 PATH="$PATH:/sbin:/usr/sbin:/usr/local/sbin" nginx -v \
217 || fatal "No nginx. Try: apt-get install nginx"
220 || 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/"
222 cadaver --version | grep -w cadaver \
223 || fatal "No cadaver. Try: apt-get install cadaver"
224 echo -n 'libattr1 xattr.h: '
225 find /usr/include -path '*/attr/xattr.h' | egrep --max-count=1 . \
226 || fatal "No libattr1 xattr.h. Try: apt-get install libattr1-dev"
227 echo -n 'libcurl curl.h: '
228 find /usr/include -path '*/curl/curl.h' | egrep --max-count=1 . \
229 || fatal "No libcurl curl.h. Try: apt-get install libcurl4-gnutls-dev"
230 echo -n 'libpq libpq-fe.h: '
231 find /usr/include -path '*/postgresql/libpq-fe.h' | egrep --max-count=1 . \
232 || fatal "No libpq libpq-fe.h. Try: apt-get install libpq-dev"
233 echo -n 'libpam pam_appl.h: '
234 find /usr/include -path '*/security/pam_appl.h' | egrep --max-count=1 . \
235 || fatal "No libpam pam_appl.h. Try: apt-get install libpam0g-dev"
236 echo -n 'postgresql: '
237 psql --version || fatal "No postgresql. Try: apt-get install postgresql postgresql-client-common"
239 which Xvfb || fatal "No xvfb. Try: apt-get install xvfb"
241 dot -V || fatal "No graphviz. Try: apt-get install graphviz"
242 echo -n 'singularity: '
243 singularity --version || fatal "No singularity. Try: arvados-server install"
244 echo -n 'docker client: '
245 docker --version || echo "No docker client. Try: arvados-server install"
246 echo -n 'docker server: '
247 docker info --format='{{.ServerVersion}}' || echo "No docker server. Try: arvados-server install"
249 if [[ "$NEED_SDK_R" = true ]]; then
252 which Rscript || fatal "No Rscript. Try: apt-get install r-base"
254 Rscript -e "library('testthat')" || fatal "No testthat. Try: apt-get install r-cran-testthat"
255 # needed for roxygen2, needed for devtools, needed for R sdk
256 pkg-config --exists libxml-2.0 || fatal "No libxml2. Try: apt-get install libxml2-dev"
257 # needed for pkgdown, builds R SDK doc pages
258 which pandoc || fatal "No pandoc. Try: apt-get install pandoc"
260 echo 'procs with /dev/fuse open:'
261 find /proc/*/fd -lname /dev/fuse 2>/dev/null | cut -d/ -f3 | xargs --no-run-if-empty ps -lywww
262 echo 'grep fuse /proc/self/mountinfo:'
263 grep fuse /proc/self/mountinfo
267 # i.e. rotate_logfile "$WORKSPACE/services/api/log/" "test.log"
268 # $BUILD_NUMBER is set by Jenkins if this script is being called as part of a Jenkins run
269 if [[ -f "$1/$2" ]]; then
270 THEDATE=`date +%Y%m%d%H%M%S`
271 mv "$1/$2" "$1/$THEDATE-$BUILD_NUMBER-$2"
272 gzip "$1/$THEDATE-$BUILD_NUMBER-$2"
286 echo >&2 "$helpmessage"
291 skip["${1%:py3}"]=1; shift
294 only["${1%:py3}"]=1; skip["${1%:py3}"]=""; shift
306 only_install="$1"; shift
316 repeat=$((${1}+0)); shift
322 suite="${arg%%_test=*}"
324 testargs["${suite%:py3}"]="$args"
327 eval export $(echo $arg | cut -d= -f1)=\"$(echo $arg | cut -d= -f2-)\"
330 echo >&2 "$0: Unrecognized option: '$arg'. Try: $0 --help"
336 # R SDK installation is very slow (~360s in a clean environment) and only
337 # required when testing it. Skip that step if it is not needed.
340 if [[ ${#only[@]} -ne 0 ]] &&
341 [[ -z "${only['sdk/R']}" && -z "${only['doc']}" ]]; then
345 if [[ ${skip["sdk/R"]} == 1 && ${skip["doc"]} == 1 ]]; then
349 if [[ $NEED_SDK_R == false ]]; then
350 echo "R SDK not needed, it will not be installed."
355 pid="$(cat "$WORKSPACE/tmp/${svc}.pid")"
356 if [[ -z "$pid" ]] || ! kill -0 "$pid"; then
357 tail $WORKSPACE/tmp/${1}*.log
358 echo "${svc} pid ${pid} not running"
361 echo "${svc} pid ${pid} ok"
366 base=$("${VENV3DIR}/bin/python3" -c "import yaml; print(list(yaml.safe_load(open('$ARVADOS_CONFIG','r'))['Clusters']['zzzzz']['Services']['$1']['InternalURLs'].keys())[0])")
367 url="$base/_health/ping"
368 if ! curl -Ss -H "Authorization: Bearer e687950a23c3a9bceec28c6223a06c79" "${url}" | tee -a /dev/stderr | grep '"OK"'; then
374 checkdiscoverydoc() {
375 dd="https://${1}/discovery/v1/apis/arvados/v1/rest"
376 if ! (set -o pipefail; curl -fsk "$dd" | grep -q ^{ ); then
377 echo >&2 "ERROR: could not retrieve discovery doc from RailsAPI at $dd"
378 tail -v $WORKSPACE/tmp/railsapi.log
385 if [[ -n "$ARVADOS_TEST_API_HOST" ]]; then
388 echo 'Starting API, controller, keepproxy, keep-web, ws, and nginx ssl proxy...'
389 if [[ ! -d "$WORKSPACE/services/api/log" ]]; then
390 mkdir -p "$WORKSPACE/services/api/log"
392 # Remove empty api.pid file if it exists
393 if [[ -f "$WORKSPACE/tmp/api.pid" && ! -s "$WORKSPACE/tmp/api.pid" ]]; then
394 rm -f "$WORKSPACE/tmp/api.pid"
396 all_services_stopped=
400 && eval $(python3 sdk/python/tests/run_test_server.py start --auth admin) \
401 && export ARVADOS_TEST_API_HOST="$ARVADOS_API_HOST" \
402 && export ARVADOS_TEST_API_INSTALLED="$$" \
403 && checkpidfile api \
404 && checkdiscoverydoc $ARVADOS_API_HOST \
405 && eval $(python3 sdk/python/tests/run_test_server.py start_nginx) \
406 && checkpidfile nginx \
407 && python3 sdk/python/tests/run_test_server.py start_controller \
408 && checkpidfile controller \
409 && checkhealth Controller \
410 && checkdiscoverydoc $ARVADOS_API_HOST \
411 && python3 sdk/python/tests/run_test_server.py start_keep_proxy \
412 && checkpidfile keepproxy \
413 && python3 sdk/python/tests/run_test_server.py start_keep-web \
414 && checkpidfile keep-web \
415 && checkhealth WebDAV \
416 && python3 sdk/python/tests/run_test_server.py start_ws \
418 && export ARVADOS_TEST_PROXY_SERVICES=1 \
419 && (env | egrep ^ARVADOS) \
421 if [[ $fail != 0 ]]; then
422 unset ARVADOS_TEST_API_HOST
428 if [[ -n "$all_services_stopped" ]]; then
431 unset ARVADOS_TEST_API_HOST ARVADOS_TEST_PROXY_SERVICES
433 && python3 sdk/python/tests/run_test_server.py stop_nginx \
434 && python3 sdk/python/tests/run_test_server.py stop_ws \
435 && python3 sdk/python/tests/run_test_server.py stop_keep-web \
436 && python3 sdk/python/tests/run_test_server.py stop_keep_proxy \
437 && python3 sdk/python/tests/run_test_server.py stop_controller \
438 && python3 sdk/python/tests/run_test_server.py stop \
439 && all_services_stopped=1
444 if [[ -n "$ignore_sigint" ]]; then
445 echo >&2 "ignored SIGINT"
448 failures+=("($(basename $0) interrupted)")
453 setup_ruby_environment() {
454 # When our "bundle install"s need to install new gems to
455 # satisfy dependencies, we want them to go where "gem install
456 # --user-install" would put them. (However, if the caller has
457 # already set GEM_HOME, we assume that's where dependencies
458 # should be installed, and we should leave it alone.)
460 if [ -z "$GEM_HOME" ]; then
461 user_gempath="$(gem env gempath)"
462 export GEM_HOME="${user_gempath%%:*}"
464 PATH="$(gem env gemdir)/bin:$PATH"
466 # When we build and install our own gems, we install them in our
467 # $GEMHOME tmpdir, and we want them to be at the front of GEM_PATH and
468 # PATH so integration tests prefer them over other versions that
469 # happen to be installed in $user_gempath, system dirs, etc.
471 tmpdir_gem_home="$(env - PATH="$PATH" HOME="$GEMHOME" gem env gempath | cut -f1 -d:)"
472 PATH="$tmpdir_gem_home/bin:$PATH"
473 export GEM_PATH="$tmpdir_gem_home:$(gem env gempath)"
475 echo "Will install dependencies to $(gem env gemdir)"
476 echo "Will install bundler and arvados gems to $tmpdir_gem_home"
477 echo "Gem search path is GEM_PATH=$GEM_PATH"
478 gem install --user --no-document --conservative --version '~> 2.4.0' bundler \
479 || fatal 'install bundler'
483 GEM_HOME="$tmpdir_gem_home" GEM_PATH="$tmpdir_gem_home" "$@"
486 gem_uninstall_if_exists() {
487 if gem list "$1\$" | egrep '^\w'; then
488 gem uninstall --force --all --executables "$1"
493 if [[ -z "${VENV3DIR:-}" ]]; then
494 fatal "setup_virtualenv called before \$VENV3DIR was set"
495 elif ! [[ -e "$VENV3DIR/bin/activate" ]]; then
496 python3 -m venv "$VENV3DIR" || fatal "virtualenv creation failed"
497 # Configure pip options we always want to use.
498 "$VENV3DIR/bin/pip" config --quiet --site set global.disable-pip-version-check true
499 "$VENV3DIR/bin/pip" config --quiet --site set global.no-input true
500 "$VENV3DIR/bin/pip" config --quiet --site set global.no-python-version-warning true
501 "$VENV3DIR/bin/pip" config --quiet --site set install.progress-bar off
502 # If we didn't have a virtualenv before, we couldn't have started any
503 # services. Set the flag used by stop_services to indicate that.
504 all_services_stopped=1
506 . "$VENV3DIR/bin/activate" || fatal "virtualenv activation failed"
510 # If dependencies like ruby, go, etc. are installed in
511 # /var/lib/arvados -- presumably by "arvados-server install" --
512 # then we want to use those versions, instead of whatever happens
513 # to be installed in /usr.
514 PATH="/var/lib/arvados/bin:${PATH}"
517 echo "WORKSPACE=$WORKSPACE"
520 if [[ -z "$temp" ]]; then
524 # Set up temporary install dirs (unless existing dirs were supplied)
525 for tmpdir in VENV3DIR GOPATH GEMHOME R_LIBS
527 if [[ -z "${!tmpdir}" ]]; then
528 eval "$tmpdir"="$temp/$tmpdir"
530 if ! [[ -d "${!tmpdir}" ]]; then
531 mkdir "${!tmpdir}" || fatal "can't create ${!tmpdir} (does $temp exist?)"
535 rm -vf "${WORKSPACE}/tmp/*.log"
540 # Make sure our compiled binaries under test override anything
541 # else that might be in the environment.
542 export PATH=$GOPATH/bin:$PATH
544 # Jenkins config requires that glob tmp/*.log match something. Ensure
545 # that happens even if we don't end up running services that set up
547 mkdir -p "${WORKSPACE}/tmp/" || fatal "could not mkdir ${WORKSPACE}/tmp"
548 touch "${WORKSPACE}/tmp/controller.log" || fatal "could not touch ${WORKSPACE}/tmp/controller.log"
550 unset http_proxy https_proxy no_proxy
552 setup_ruby_environment
559 go mod download || fatal "Go deps failed"
560 which goimports >/dev/null || go install golang.org/x/tools/cmd/goimports@latest || fatal "Go setup failed"
561 # parameterized and pytest are direct dependencies of Python tests.
562 # PyYAML is a test requirement used by run_test_server.py and needed for
563 # other, non-Python tests.
564 # pdoc is needed to build PySDK documentation.
565 # pip >= 20.3 is necessary for modern dependency resolution.
566 # setuptools is our chosen Python build tool.
567 # wheel modernizes the venv (as of early 2024) and makes it more closely
568 # match our package build environment.
569 pip install parameterized pdoc "pip>=20.3" pytest PyYAML setuptools wheel ||
570 fatal "virtualenv package installs failed"
578 if [[ "$remain" -gt 1 ]]; then
579 remain=$((${remain}-1))
580 title "(repeating ${remain} more times)"
584 elif [[ "$retry" == 1 ]]; then
585 read -p 'Try again? [Y/n] ' x
586 if [[ "$x" != "y" ]] && [[ "$x" != "" ]]
598 services/workbench2_units | services/workbench2_integration)
599 suite=services/workbench2
605 if [[ -n "${skip[$suite]}" || \
606 -n "${skip[$1]}" || \
607 (${#only[@]} -ne 0 && ${only[$suite]} -eq 0 && ${only[$1]} -eq 0) ]]; then
613 check_arvados_config "$1"
616 | arvados_version.py \
617 | cmd/arvados-package \
622 | lib/cloud/cloudtest \
625 | lib/dispatchcloud/sshexecutor \
626 | lib/dispatchcloud/worker \
628 | services/workbench2_integration \
629 | services/workbench2_units \
631 check_arvados_config "$1"
632 # don't care whether services are running
635 check_arvados_config "$1"
636 if ! start_services; then
637 checkexit 1 "$1 tests"
638 title "test $1 -- failed to start services"
643 retry do_test_once ${@}
647 version=${ARVADOS_VERSION:-$(git log -n1 --format=%H)-dev}
648 echo "-X git.arvados.org/arvados.git/lib/cmd.version=${version} -X main.version=${version} -s -w"
658 if [[ "$2" == "go" ]]
660 covername="coverage-$(echo "$1" | sed -e 's/\//_/g')"
661 coverflags=("-covermode=count" "-coverprofile=$WORKSPACE/tmp/.$covername.tmp")
663 if [[ "$1" == "cmd/arvados-package" ]]; then
664 testflags+=("-timeout" "20m")
666 # We do "go install" here to catch compilation errors
667 # before trying "go test". Otherwise, coverage-reporting
668 # mode makes Go show the wrong line numbers when reporting
669 # compilation errors.
670 go install -ldflags "$(go_ldflags)" "$WORKSPACE/$1" && \
671 cd "$WORKSPACE/$1" && \
672 if [[ -n "${testargs[$1]}" ]]
674 # "go test -check.vv giturl" doesn't work, but this
676 go test ${short:+-short} ${testflags[@]} ${testargs[$1]}
678 # The above form gets verbose even when testargs is
679 # empty, so use this form in such cases:
680 go test ${short:+-short} ${testflags[@]} ${coverflags[@]} "git.arvados.org/arvados.git/$1"
683 if [[ -f "$WORKSPACE/tmp/.$covername.tmp" ]]
685 go tool cover -html="$WORKSPACE/tmp/.$covername.tmp" -o "$WORKSPACE/tmp/$covername.html"
686 rm "$WORKSPACE/tmp/.$covername.tmp"
688 [[ $result = 0 ]] && gofmt -e -d *.go
689 elif [[ "$2" == "pip" ]]
692 cd "$WORKSPACE/$1" && pip install . && while :
694 tries=$((${tries}+1))
695 python3 -m pytest ${testargs[$1]}
697 # pytest uses exit code 2 to mean "test collection failed."
698 # See discussion in FUSE's IntegrationTest and MountTestBase.
699 if [[ ${tries} < 3 && ${result} == 2 ]]
701 printf '\n*****\n%s tests exited with code 2 -- retrying\n*****\n\n' "$1"
707 elif [[ "$2" != "" ]]
714 checkexit $result "$1 tests"
715 title "test $1 -- `timer`"
719 check_arvados_config() {
720 if [[ "$1" = "env" ]] ; then
723 if [[ -z "$ARVADOS_CONFIG" ]] ; then
725 eval $(python3 sdk/python/tests/run_test_server.py setup_config)
730 if [[ -n ${skip["install_$1"]} || -n "${skip[install]}" || ( -n "${only_install}" && "${only_install}" != "${1}" && "${only_install}" != "${2}" ) ]]; then
733 check_arvados_config "$1"
734 retry do_install_once ${@}
742 if [[ "$2" == "go" ]]
744 go install -ldflags "$(go_ldflags)" "$WORKSPACE/$1"
745 elif [[ "$2" == "pip" ]]
747 pip install "$WORKSPACE/$1"
748 elif [[ "$2" != "" ]]
755 checkexit $result "$1 install"
756 title "install $1 -- `timer`"
760 bundle_install_trylocal() {
763 echo "(Running bundle install --local. 'could not find package' messages are OK.)"
764 if ! bundle install --local --no-deployment; then
765 echo "(Running bundle install again, without --local.)"
766 bundle install --no-deployment
773 cd "$WORKSPACE/doc" \
774 && bundle_install_trylocal \
781 with_test_gemset gem_uninstall_if_exists "$gemname" \
782 && cd "$WORKSPACE/$srcpath" \
783 && bundle_install_trylocal \
784 && gem build "$gemname.gemspec" \
785 && with_test_gemset gem install --no-document $(ls -t "$gemname"-*.gem|head -n1)
789 install_gem arvados sdk/ruby
792 install_sdk/ruby-google-api-client() {
793 install_gem arvados-google-api-client sdk/ruby-google-api-client
797 if [[ "$NEED_SDK_R" = true ]]; then
798 cd "$WORKSPACE/sdk/R" \
799 && Rscript --vanilla install_deps.R
804 install_gem arvados-cli sdk/cli
807 install_services/login-sync() {
808 install_gem arvados-google-api-client sdk/ruby-google-api-client
809 install_gem arvados sdk/ruby
810 install_gem arvados-login-sync services/login-sync
813 install_services/api() {
815 check_arvados_config "services/api"
816 cd "$WORKSPACE/services/api" \
817 && RAILS_ENV=test bundle_install_trylocal \
820 rm -f config/environments/test.rb
821 cp config/environments/test.rb.example config/environments/test.rb
823 # Clear out any lingering postgresql connections to the test
824 # database, so that we can drop it. This assumes the current user
825 # is a postgresql superuser.
826 cd "$WORKSPACE/services/api" \
827 && test_database=$("${VENV3DIR}/bin/python3" -c "import yaml; print(yaml.safe_load(open('$ARVADOS_CONFIG','r'))['Clusters']['zzzzz']['PostgreSQL']['Connection']['dbname'])") \
828 && 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
830 mkdir -p "$WORKSPACE/services/api/tmp/pids"
832 cert="$WORKSPACE/services/api/tmp/self-signed"
833 if [[ ! -e "$cert.pem" || "$(date -r "$cert.pem" +%s)" -lt 1512659226 ]]; then
835 dir="$WORKSPACE/services/api/tmp"
837 openssl req -newkey rsa:2048 -nodes -subj '/C=US/ST=State/L=City/CN=localhost' -out "$cert.csr" -keyout "$cert.key" </dev/null
838 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')
844 cd "$WORKSPACE/services/api"
845 export RAILS_ENV=test
846 if bin/rails db:environment:set ; then
850 bin/rake db:fixtures:load
854 declare -a pythonstuff
856 # The ordering of sdk/python, tools/crunchstat-summary, and
857 # sdk/cwl here is significant. See
858 # https://dev.arvados.org/issues/19744#note-26
860 tools/crunchstat-summary
862 services/dockercleaner
867 gostuff=($(cd "$WORKSPACE" && git ls-files | grep '\.go$' | sed -e 's/\/[^\/]*$//' | sort -u))
869 install_services/workbench2() {
870 cd "$WORKSPACE/services/workbench2" \
871 && make yarn-install ARVADOS_DIRECTORY="${WORKSPACE}"
875 local arvados_api_host=pirca.arvadosapi.com && \
876 env -C "$WORKSPACE/doc" \
877 bundle exec rake linkchecker \
878 arvados_api_host="$arvados_api_host" \
879 arvados_workbench_host="https://workbench.$arvados_api_host" \
880 baseurl="file://$WORKSPACE/doc/.site/" \
885 cd "$WORKSPACE" || return 1
886 dirs=$(ls -d */ | egrep -v 'vendor|tmp')
887 [[ -z "$(gofmt -e -d $dirs | tee -a /dev/stderr)" ]]
888 go vet -composites=false ./...
891 test_arvados_version.py() {
894 while read -d "" fn; do
895 if [[ -z "$orig_fn" ]]; then
897 elif ! cmp "$orig_fn" "$fn"; then
898 fail_count=$(( $fail_count + 1 ))
899 printf "FAIL: %s and %s are not identical\n" "$orig_fn" "$fn"
901 done < <(git -C "$WORKSPACE" ls-files -z | grep -z '/arvados_version\.py$')
903 "") return 66 ;; # EX_NOINPUT
904 *) return "$fail_count" ;;
908 test_services/api() {
909 rm -f "$WORKSPACE/services/api/git-commit.version"
910 cd "$WORKSPACE/services/api" \
911 && eval env RAILS_ENV=test ${short:+RAILS_TEST_SHORT=1} bundle exec rake test TESTOPTS=\'-v -d\' ${testargs[services/api]}
915 cd "$WORKSPACE/sdk/ruby" \
916 && bundle exec rake test TESTOPTS=-v ${testargs[sdk/ruby]}
919 test_sdk/ruby-google-api-client() {
920 echo "*** note \`test sdk/ruby-google-api-client\` does not actually run any tests, see https://dev.arvados.org/issues/20993 ***"
925 if [[ "$NEED_SDK_R" = true ]]; then
926 cd "$WORKSPACE/sdk/R" \
927 && Rscript --vanilla run_test.R
932 cd "$WORKSPACE/sdk/cli" \
933 && mkdir -p /tmp/keep \
934 && KEEP_LOCAL_STORE=/tmp/keep bundle exec rake test TESTOPTS=-v ${testargs[sdk/cli]}
938 cd "$WORKSPACE/sdk/java-v2" && gradle test ${testargs[sdk/java-v2]}
941 test_services/login-sync() {
942 cd "$WORKSPACE/services/login-sync" \
943 && bundle exec rake test TESTOPTS=-v ${testargs[services/login-sync]}
946 test_services/workbench2_units() {
947 cd "$WORKSPACE/services/workbench2" && make unit-tests ARVADOS_DIRECTORY="${WORKSPACE}" WORKSPACE="$(pwd)" ${testargs[services/workbench2]}
950 test_services/workbench2_integration() {
952 FAIL_FAST_ENABLED=false
953 if [[ -n ${interactive} ]]; then
955 FAIL_FAST_ENABLED=true
957 cd "$WORKSPACE/services/workbench2" && make integration-tests ARVADOS_DIRECTORY="${WORKSPACE}" \
959 INTERACTIVE=$INTERACTIVE \
960 CYPRESS_FAIL_FAST_ENABLED=$FAIL_FAST_ENABLED \
961 ${testargs[services/workbench2]}
965 # Install parts needed by test suites
967 # Many other components rely on PySDK's run_test_server.py, which relies on
968 # the SDK itself, so install that first.
969 do_install sdk/python pip
970 # lib/controller integration tests depend on arv-mount to run containers.
971 do_install services/fuse pip
972 # sdk/cwl depends on crunchstat-summary.
973 do_install tools/crunchstat-summary pip
974 do_install cmd/arvados-server go
975 do_install sdk/ruby-google-api-client
978 do_install services/api
979 do_install services/keepproxy go
980 do_install services/keep-web go
986 do_install sdk/ruby-google-api-client
990 do_install services/login-sync
992 if [[ -z ${skip[python3]} ]]; then
993 for pkg_dir in "${pythonstuff[@]}"
995 do_install "$pkg_dir" pip
998 for pkg_dir in "${gostuff[@]}"
1000 do_install "$pkg_dir" go
1002 do_install services/api
1003 do_install services/workbench2
1008 do_test services/api
1010 do_test arvados_version.py
1012 do_test sdk/ruby-google-api-client
1016 do_test services/login-sync
1019 if [[ -z ${skip[python3]} ]]; then
1020 for pkg_dir in "${pythonstuff[@]}"
1022 do_test "$pkg_dir" pip
1025 for pkg_dir in "${gostuff[@]}"
1027 do_test "$pkg_dir" go
1029 do_test services/workbench2_units
1030 do_test services/workbench2_integration
1035 for g in "${gostuff[@]}"
1041 help_interactive() {
1042 echo "== Interactive commands:"
1043 echo "TARGET (short for 'test DIR')"
1045 echo "10 test TARGET (run test 10 times)"
1046 echo "test TARGET -check.vv (pass arguments to test)"
1047 echo "install TARGET"
1048 echo "install env (go/python libs)"
1049 echo "install deps (go/python libs + arvados components needed for integration tests)"
1050 echo "reset (...services used by integration tests)"
1052 echo "== Test targets:"
1053 echo "${!testfuncargs[@]}" | tr ' ' '\n' | sort | column
1058 declare -A testfuncargs=()
1059 for g in "${gostuff[@]}"; do
1060 testfuncargs[$g]="$g go"
1062 for p in "${pythonstuff[@]}"; do
1063 testfuncargs[$p]="$p pip"
1066 testfuncargs["sdk/cli"]="sdk/cli"
1067 testfuncargs["sdk/R"]="sdk/R"
1068 testfuncargs["sdk/java-v2"]="sdk/java-v2"
1070 if [[ -z ${interactive} ]]; then
1079 if [[ "$TERM" = dumb ]]; then
1080 # assume emacs, or something, is offering a history buffer
1081 # and pre-populating the command will only cause trouble
1083 elif [[ ! -e "$GOPATH/bin/arvados-server" ]]; then
1084 nextcmd="install deps"
1092 HISTFILE="$WORKSPACE/tmp/.history"
1095 while read -p 'What next? ' -e -i "$nextcmd" nextcmd; do
1096 history -s "$nextcmd"
1099 if [[ "${nextcmd}" =~ ^[0-9] ]]; then
1100 read count nextcmd <<<"${nextcmd}"
1102 read verb target opts <<<"${nextcmd}"
1103 target="${target%/}"
1104 target="${target/\/:/:}"
1105 # Remove old Python version suffix for backwards compatibility
1106 target="${target%:py3}"
1123 testargs["$target"]="${opts}"
1124 tt="${testfuncargs[${target}]}"
1126 while [ $count -gt 0 ]; do
1137 if [[ ${#successes[@]} -gt 0 || ${#failures[@]} -gt 0 ]]; then