16029: Enhances orquestration script in various ways.
[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() {
9     set -x
10     kill ${arvboot_PID} ${consume_stdout_PID} ${wb2_PID} ${consume_wb2_stdout_PID}
11     wait ${arvboot_PID} ${consume_stdout_PID} ${wb2_PID} ${consume_wb2_stdout_PID} || true
12     rm -rf ${ARVADOS_DIR}
13     echo >&2 "done"
14 }
15
16 random_free_port() {
17     while port=$(shuf -n1 -i $(cat /proc/sys/net/ipv4/ip_local_port_range | tr '\011' '-'))
18     netstat -atun | grep -q ":$port\s" ; do
19         continue
20     done
21     echo $port
22 }
23
24 # Allow self-signed certs on 'wait-on'
25 export NODE_TLS_REJECT_UNAUTHORIZED=0
26
27 ARVADOS_DIR=`mktemp -d`
28 ARVADOS_LOG=${ARVADOS_DIR}/arvados.log
29 WB2_DIR=`pwd`
30 ARVADOS_CONF=${WB2_DIR}/tools/arvados_config.yml
31
32 if [ -f "${WB2_DIR}/public/config.json" ]; then
33     echo "ERROR: Cannot run with Workbench2's public/config.json file"
34     exit 1
35 fi
36
37 if [ ! -d "${ARVADOS_DIR}/lib" ]; then
38     echo "Downloading arvados..."
39     git clone https://git.arvados.org/arvados.git ${ARVADOS_DIR} || exit 1
40 fi
41
42 echo "Building & installing arvados-server..."
43 cd ${ARVADOS_DIR}
44 go mod download || exit 1
45 cd cmd/arvados-server
46 go install
47 cd -
48
49 echo "Installing dev dependencies..."
50 ~/go/bin/arvados-server install -type test || exit 1
51
52 echo "Launching arvados in test mode..."
53 coproc arvboot (~/go/bin/arvados-server boot \
54     -type test \
55     -config ${ARVADOS_CONF} \
56     -own-temporary-database \
57     -timeout 20m 2> ${ARVADOS_LOG})
58 trap cleanup ERR EXIT
59
60 read controllerURL <&"${arvboot[0]}" || exit 1
61 echo "Arvados up and running at ${controllerURL}"
62 IFS='/' ; read -ra controllerHostPort <<< "${controllerURL}" ; unset IFS
63 controllerHostPort=${controllerHostPort[2]}
64
65 # Copy coproc's stdout to stderr, to ensure `arvados-server boot`
66 # doesn't get blocked trying to write stdout.
67 exec 7<&"${arvboot[0]}"; coproc consume_stdout (cat <&7 >&2)
68
69 cd ${WB2_DIR}
70 echo "Launching workbench2..."
71 WB2_PORT=`random_free_port`
72 coproc wb2 (PORT=${WB2_PORT} \
73     REACT_APP_ARVADOS_API_HOST=${controllerHostPort} \
74     yarn start)
75 exec 8<&"${wb2[0]}"; coproc consume_wb2_stdout (cat <&8 >&2)
76
77 # Wait for workbench2 to be up.
78 # Using https-get to avoid false positive 'ready' detection.
79 yarn run wait-on --timeout 300000 https-get://localhost:${WB2_PORT} || exit 1
80
81 echo "Running tests..."
82 CYPRESS_system_token=systemusertesttoken1234567890aoeuidhtnsqjkxbmwvzpy \
83     CYPRESS_controller_url=${controllerURL} \
84     CYPRESS_BASE_URL=https://localhost:${WB2_PORT} \
85     yarn run cypress run