16029: Adds orquestration script.
[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 random_free_port() {
7     while port=$(shuf -n1 -i $(cat /proc/sys/net/ipv4/ip_local_port_range | tr '\011' '-'))
8     netstat -atun | grep -q ":$port\s" ; do
9         continue
10     done
11     echo $port
12 }
13
14 # Allow self-signed certs on 'wait-on'
15 export NODE_TLS_REJECT_UNAUTHORIZED=0
16
17 WORKDIR=`mktemp -d`
18 ARVADOS_LOG=${WORKDIR}/arvados.log
19 ARVADOS_CONF=`pwd`/tools/arvados_config.yml
20
21 if [ ! -e "${WORKDIR}/lib" ]; then
22     echo "Downloading arvados..."
23     git clone https://git.arvados.org/arvados.git ${WORKDIR} || exit 1
24 fi
25
26 echo "Building & installing arvados-server..."
27 cd ${WORKDIR}
28 go mod download || exit 1
29
30 echo "Installing dev dependencies..."
31 sudo go run ./cmd/arvados-server install -type test || exit 1
32
33 echo "Running arvados in test mode..."
34 ARVADOS_PORT=`random_free_port`
35 go run ./cmd/arvados-server boot \
36     -config ${ARVADOS_CONF} \
37     -type test \
38     -own-temporary-database \
39     -controller-address :${ARVADOS_PORT} \
40     -listen-host localhost > ${ARVADOS_LOG} 2>&1 &
41
42 cd -
43 echo "Running workbench2..."
44 WB2_PORT=`random_free_port`
45 PORT=${WB2_PORT} REACT_APP_ARVADOS_API_HOST=localhost:${ARVADOS_PORT} \
46     yarn start &
47
48 # Wait for arvados & workbench2 to be up.
49 # Using https-get to avoid false positive 'ready' detection.
50 yarn run wait-on https-get://localhost:${ARVADOS_PORT}/discovery/v1/apis/arvados/v1/rest
51 yarn run wait-on https-get://localhost:${WB2_PORT}
52
53 echo "Running tests..."
54 CYPRESS_system_token=systemusertesttoken1234567890aoeuidhtnsqjkxbmwvzpy \
55     CYPRESS_controller_url=https://localhost:${ARVADOS_PORT} \
56     CYPRESS_BASE_URL=https://localhost:${WB2_PORT} \
57     yarn run cypress run
58 TEST_EXIT_CODE=$?
59
60 # Cleanup
61 rm -rf ${WORKDIR}
62
63 exit ${TEST_EXIT_CODE}