19899: Remove webdav cache disable from cypress config to properly test cache-control...
[arvados.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     set +e +o pipefail
11     kill ${arvboot_PID} ${consume_stdout_PID} ${wb2_PID} ${consume_wb2_stdout_PID}
12     wait ${arvboot_PID} ${consume_stdout_PID} ${wb2_PID} ${consume_wb2_stdout_PID} || true
13     if [ ${CLEANUP_ARVADOS_DIR} -eq 1 ]; then
14         rm -rf ${ARVADOS_DIR}
15     fi
16     echo >&2 "done"
17 }
18
19 random_free_port() {
20     while port=$(shuf -n1 -i $(cat /proc/sys/net/ipv4/ip_local_port_range | tr '\011' '-'))
21     netstat -atun | grep -q ":$port\s" ; do
22         continue
23     done
24     echo $port
25 }
26
27 usage() {
28     echo "Usage: ${0} [options]"
29     echo "Options:"
30     echo "  -i            Run Cypress in interactive mode."
31     echo "  -a PATH       Arvados dir. If PATH doesn't exist, a repo clone is downloaded there."
32     echo "  -w PATH       Workbench2 dir. Default: Current working directory"
33     exit 0
34 }
35
36 # Allow self-signed certs on 'wait-on'
37 export NODE_TLS_REJECT_UNAUTHORIZED=0
38
39 ARVADOS_DIR="unset"
40 CLEANUP_ARVADOS_DIR=0
41 CYPRESS_MODE="run"
42 WB2_DIR=`pwd`
43
44 while getopts "ia:w:" o; do
45     case "${o}" in
46         i)
47             # Interactive mode
48             CYPRESS_MODE="open"
49             ;;
50         a)
51             ARVADOS_DIR=${OPTARG}
52             ;;
53         w)
54             WB2_DIR=${OPTARG}
55             ;;
56         *)
57             echo "Invalid Option: -$OPTARG" 1>&2
58             usage
59             ;;
60     esac
61 done
62 shift $((OPTIND-1))
63
64 if [ "${ARVADOS_DIR}" = "unset" ]; then
65   echo "ARVADOS_DIR is unset, creating a temporary directory for new checkout"
66   ARVADOS_DIR=`mktemp -d`
67 fi
68
69 echo "ARVADOS_DIR is ${ARVADOS_DIR}"
70
71 ARVADOS_LOG=${ARVADOS_DIR}/arvados.log
72 ARVADOS_CONF=${WB2_DIR}/tools/arvados_config.yml
73 VOCABULARY_CONF=${WB2_DIR}/tools/example-vocabulary.json
74
75 if [ ! -f "${WB2_DIR}/src/index.tsx" ]; then
76     echo "ERROR: '${WB2_DIR}' isn't workbench2's directory"
77     usage
78 fi
79
80 if [ ! -f ${ARVADOS_CONF} ]; then
81     echo "ERROR: Arvados config file ${ARVADOS_CONF} not found"
82     exit 1
83 fi
84
85 if [ -f "${WB2_DIR}/public/config.json" ]; then
86     echo "ERROR: Please move public/config.json file out of the way"
87     exit 1
88 fi
89
90 if [ ! -d "${ARVADOS_DIR}/.git" ]; then
91     mkdir -p ${ARVADOS_DIR} || exit 1
92     CLEANUP_ARVADOS_DIR=1
93     echo "Downloading arvados..."
94     git clone https://git.arvados.org/arvados.git ${ARVADOS_DIR} || exit 1
95 fi
96
97 echo "Building & installing arvados-server..."
98 cd ${ARVADOS_DIR}
99 go mod download || exit 1
100 cd cmd/arvados-server
101 go install
102 cd -
103
104 echo "Installing dev dependencies..."
105 ~/go/bin/arvados-server install -type test || exit 1
106
107 echo "Launching arvados in test mode..."
108 TMPSUBDIR=$(mktemp -d -p /tmp | cut -d \/ -f3) # Removes the /tmp/ part for the regex below
109 TMPDIR=/tmp/${TMPSUBDIR}
110 cp ${VOCABULARY_CONF} ${TMPDIR}/voc.json
111 cp ${ARVADOS_CONF} ${TMPDIR}/arvados.yml
112 sed -i "s/VocabularyPath: \".*\"/VocabularyPath: \"\/tmp\/${TMPSUBDIR}\/voc.json\"/" ${TMPDIR}/arvados.yml
113 coproc arvboot (~/go/bin/arvados-server boot \
114     -type test \
115     -config ${TMPDIR}/arvados.yml \
116     -no-workbench1 \
117     -no-workbench2 \
118     -own-temporary-database \
119     -timeout 20m 2> ${ARVADOS_LOG})
120 trap cleanup ERR EXIT
121
122 read controllerInfo <&"${arvboot[0]}" || exit 1
123 controllerURL=`echo "$controllerInfo" | awk '{print $1;}'`;
124 echo "Arvados up and running at ${controllerURL}"
125 IFS='/' ; read -ra controllerHostPort <<< "${controllerURL}" ; unset IFS
126 controllerHostPort=${controllerHostPort[2]}
127
128 # Copy coproc's stdout to stderr, to ensure `arvados-server boot`
129 # doesn't get blocked trying to write stdout.
130 exec 7<&"${arvboot[0]}"; coproc consume_stdout (cat <&7 >&2)
131
132 cd ${WB2_DIR}
133 echo "Launching workbench2..."
134 WB2_PORT=`random_free_port`
135 coproc wb2 (PORT=${WB2_PORT} \
136     REACT_APP_ARVADOS_API_HOST=${controllerHostPort} \
137     yarn start)
138 exec 8<&"${wb2[0]}"; coproc consume_wb2_stdout (cat <&8 >&2)
139
140 # Wait for workbench2 to be up.
141 # Using https-get to avoid false positive 'ready' detection.
142 yarn run wait-on --timeout 300000 https-get://localhost:${WB2_PORT} || exit 1
143
144 echo "Running tests..."
145 CYPRESS_system_token=systemusertesttoken1234567890aoeuidhtnsqjkxbmwvzpy \
146     CYPRESS_controller_url=${controllerURL} \
147     CYPRESS_BASE_URL=https://localhost:${WB2_PORT} \
148     yarn run cypress ${CYPRESS_MODE}