16029: Working on a better way of launching arvados boot. (WIP)
[arvados-workbench2.git] / tools / run-integration-tests.sh
1 #!/bin/bash
2 # Copyright (C) The Arvados Authors. All rights reserved.
3 #
4 # SPDX-License-Identifier: AGPL-3.0
5
6 set -e -o pipefail
7
8 cleanup_arvboot() {
9     set -x
10     kill ${arvboot_PID} ${consume_stdout_PID}
11     wait ${arvboot_PID} ${consume_stdout_PID} || true
12     echo >&2 "done"
13 }
14
15 random_free_port() {
16     while port=$(shuf -n1 -i $(cat /proc/sys/net/ipv4/ip_local_port_range | tr '\011' '-'))
17     netstat -atun | grep -q ":$port\s" ; do
18         continue
19     done
20     echo $port
21 }
22
23 # Allow self-signed certs on 'wait-on'
24 export NODE_TLS_REJECT_UNAUTHORIZED=0
25
26 WORKDIR=`mktemp -d`
27 WORKDIR=/tmp/arvboot # For script testing purposes...
28 ARVADOS_LOG=${WORKDIR}/arvados.log
29 ARVADOS_CONF=`pwd`/tools/arvados_config.yml
30
31 if [ ! -e "${WORKDIR}/lib" ]; then
32     echo "Downloading arvados..."
33     git clone https://git.arvados.org/arvados.git ${WORKDIR} || exit 1
34 fi
35
36 echo "Building & installing arvados-server..."
37 cd ${WORKDIR}
38 go mod download || exit 1
39 cd cmd/arvados-server
40 go install
41 cd -
42
43 echo "Installing dev dependencies..."
44 ~/go/bin/arvados-server install -type test || exit 1
45
46 echo "Running arvados in test mode..."
47 # ARVADOS_PORT=`random_free_port`
48 # go run ./cmd/arvados-server boot \
49 #     -config ${ARVADOS_CONF} \
50 #     -type test \
51 #     -own-temporary-database \
52 #     -controller-address :${ARVADOS_PORT} \
53 #     -listen-host localhost > ${ARVADOS_LOG} 2>&1 &
54 coproc arvboot (~/go/bin/arvados-server boot \
55     -type test                      \
56     -config ${ARVADOS_CONF}         \
57     -own-temporary-database         \
58     -timeout 20m)
59 trap cleanup_arvboot ERR EXIT
60
61 read controllerURL <&"${arvboot[0]}"
62
63 # Copy coproc's stdout to stderr, to ensure `arvados-server boot`
64 # doesn't get blocked trying to write stdout.
65 exec 7<&"${arvbboot[0]}"; coproc consume_stdout (cat <&7 >&2)
66
67 cd -
68 echo "Running workbench2..."
69 WB2_PORT=`random_free_port`
70 PORT=${WB2_PORT} REACT_APP_ARVADOS_API_HOST=${controllerURL} \
71     yarn start &
72
73 # Wait for arvados & workbench2 to be up.
74 # Using https-get to avoid false positive 'ready' detection.
75 # yarn run wait-on --httpTimeout 300000 https-get://localhost:${ARVADOS_PORT}/discovery/v1/apis/arvados/v1/rest ||
76 yarn run wait-on --httpTimeout 300000 https-get://localhost:${WB2_PORT}
77
78 echo "Running tests..."
79 CYPRESS_system_token=systemusertesttoken1234567890aoeuidhtnsqjkxbmwvzpy \
80     CYPRESS_controller_url=${controllerURL} \
81     CYPRESS_BASE_URL=https://localhost:${WB2_PORT} \
82     yarn run cypress run
83 TEST_EXIT_CODE=$?
84
85 # Cleanup
86 rm -rf ${WORKDIR}
87
88 exit ${TEST_EXIT_CODE}