1 | #!/usr/bin/env bash
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 | set -e
|
20 | set -o pipefail
|
21 |
|
22 | SCRIPTDIR=$(cd $(dirname "$0") && pwd)
|
23 |
|
24 | if [ -n "$NYC" ]; then
|
25 | if [ -z "$TRAVIS_JOB_ID" ]; then
|
26 |
|
27 |
|
28 | "$SCRIPTDIR"/../../../tools/codecov/instrument.sh
|
29 |
|
30 |
|
31 | rm -rf .nyc_output
|
32 | fi
|
33 | fi
|
34 |
|
35 | if [ -z "$MONOREPO_MODE" ]; then
|
36 | echo "running as external custom client"
|
37 | ROOT="$SCRIPTDIR"/../..
|
38 | export TEST_SUITE_ROOT="$ROOT"/node_modules/@kui-shell
|
39 | export TEST_ROOT="$TEST_SUITE_ROOT"/test
|
40 | cd "$SCRIPTDIR"
|
41 | else
|
42 | ROOT="$SCRIPTDIR"/../../..
|
43 | echo "running in monorepo $ROOT"
|
44 | export TEST_SUITE_ROOT="$ROOT"/node_modules/@kui-shell
|
45 | export TEST_ROOT="$ROOT"/packages/test
|
46 | fi
|
47 |
|
48 | if [ -z "$API_HOST" ]; then
|
49 | if [ -f ~/.wskprops ]; then
|
50 | . ~/.wskprops
|
51 | export API_HOST=$APIHOST
|
52 | elif [ -z "$LAYERS" ]; then
|
53 | export EXCLUDE_OW_TEST=true
|
54 | fi
|
55 | fi
|
56 |
|
57 | if [ ! -f ~/.wskprops ]; then
|
58 | echo "APIHOST=$API_HOST" > ~/.wskprops
|
59 | echo "INSECURE_SSL=true" >> ~/.wskprops
|
60 | fi
|
61 |
|
62 | export PATH=./node_modules/.bin:$PATH
|
63 |
|
64 |
|
65 | if [ $# -ne 0 ]; then
|
66 |
|
67 | WHICH=$@
|
68 | elif [ -n "$LAYERS" ]; then
|
69 |
|
70 | WHICH=$LAYERS
|
71 | else
|
72 |
|
73 | WHICH=""
|
74 | fi
|
75 |
|
76 | echo "Running these layers: $# $WHICH"
|
77 |
|
78 | children=()
|
79 | childrenNames=()
|
80 |
|
81 | function kill_them_all() {
|
82 | children=("$@")
|
83 | for job in "${children[@]}"; do
|
84 | echo "killing ${job}"
|
85 | kill -9 ${job}
|
86 | done
|
87 | exit
|
88 | }
|
89 | trap kill_them_all INT
|
90 |
|
91 | idx=${PORT_OFFSET_BASE-${PORT_OFFSET-1}}
|
92 | if [ -z "$WHICH" ]; then
|
93 | (LAYER=$LAYER DISPLAY=":$idx" PORT_OFFSET=$idx "$TEST_ROOT"/bin/runTest.sh 2>&1)
|
94 | else
|
95 | for i in $WHICH; do
|
96 | LAYER=`basename $i`
|
97 | echo "spawning mocha layer $LAYER PORT_OFFSET=$idx"
|
98 | (LAYER=$LAYER DISPLAY=":$idx" PORT_OFFSET=$idx "$TEST_ROOT"/bin/runTest.sh 2>&1) &
|
99 | children+=("$!")
|
100 | childrenNames+=("$LAYER")
|
101 | idx=$((idx+1))
|
102 | done
|
103 | fi
|
104 |
|
105 | function wait_and_get_exit_codes() {
|
106 | children=("$@")
|
107 | EXIT_CODE=0
|
108 |
|
109 | for jobIdx in "${!children[@]}"; do
|
110 | job="${children[$jobIdx]}"
|
111 | jobName="${childrenNames[$jobIdx]}"
|
112 | echo "$(tput setaf 3)waiting on ${jobName} with PID ${job}$(tput sgr0)"
|
113 | CODE=0;
|
114 | wait ${job} || CODE=$?
|
115 | if [[ "${CODE}" != "0" ]]; then
|
116 | echo "$(tput setaf 1)failing: job ${jobName} exited with a non-zero code ${CODE}$(tput sgr0)"
|
117 | EXIT_CODE=1;
|
118 | else
|
119 | echo "$(tput setaf 2)ok: mocha job ${jobName} exited with success$(tput sgr0)"
|
120 | fi
|
121 | done
|
122 | }
|
123 | wait_and_get_exit_codes "${children[@]}"
|
124 |
|
125 |
|
126 | if [ $EXIT_CODE == 0 ]; then
|
127 | if [ -n "$NYC" ]; then
|
128 |
|
129 | if [ -z "$TRAVIS_JOB_ID" ]; then
|
130 | set +e
|
131 | "$SCRIPTDIR"/../../../tools/codecov/report.sh
|
132 | fi
|
133 | fi
|
134 | fi
|
135 |
|
136 | echo "runMochaLayers finished with ${EXIT_CODE-0}"
|
137 | exit "${EXIT_CODE-0}"
|