Skip to content

Commit 3a4ff80

Browse files
authored
Add integration test to spark workloads and bash script to run all examples
1 parent 5b91035 commit 3a4ff80

File tree

24 files changed

+1194
-278
lines changed

24 files changed

+1194
-278
lines changed

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ lint:
116116
find-missing-version:
117117
@./build/find-missing-version.sh
118118

119+
test-examples:
120+
$(MAKE) registry-all
121+
@./build/test-examples.sh
122+
119123
###############
120124
# CI Commands #
121125
###############

build/test-examples.sh

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#!/bin/bash
2+
3+
# Copyright 2019 Cortex Labs, Inc.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
set -eou pipefail
18+
19+
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")"/.. >/dev/null && pwd)"
20+
CORTEX="$ROOT/bin/cortex"
21+
22+
for example in $ROOT/examples/*/app.yaml; do
23+
timer=1200
24+
example_base_dir=$(dirname "${example}")
25+
retry="false"
26+
27+
cd $example_base_dir
28+
echo "Deploying $example_base_dir"
29+
$CORTEX refresh
30+
31+
api_names="$($CORTEX get api | sed '1,2d' | sed '/^$/d' | tr -s ' ' | cut -f 1 -d " ")"
32+
sample="$(find . -name "*.json")"
33+
34+
while true; do
35+
current_status="$($CORTEX status)"
36+
echo "$current_status"
37+
38+
error_count="$(echo $current_status | { grep "error" || test $? = 1; } | wc -l)"
39+
# accomodate transient error `error: failed to connect to operator...`
40+
if [ $error_count -gt "0" ] && [[ ! $current_status =~ ^error\:\ failed\ to\ connect\ to\ the\ operator.* ]]; then
41+
exit 1
42+
fi
43+
44+
ready_count="$($CORTEX get api | sed '1,2d' | sed '/^$/d' | { grep "ready" || test $? = 1; } | wc -l)"
45+
total_count="$($CORTEX get api | sed '1,2d' | sed '/^$/d' | wc -l)"
46+
47+
sleep 15 # account for API startup delay
48+
49+
if [ "$ready_count" == "$total_count" ] && [ $total_count -ne "0" ]; then
50+
for api_name in $api_names; do
51+
echo "Running cx predict $api_name $sample"
52+
result="$($CORTEX predict $api_name $sample)"
53+
prediction_exit_code=$?
54+
echo "$result"
55+
if [ $prediction_exit_code -ne 0 ]; then
56+
# accomodate transient error `error: failed to connect to operator...`
57+
# handle `error: api ... is updating` error caused when the API status is set to `ready` but it actually isn't
58+
if [[ $result =~ ^error\:\ failed\ to\ connect\ to\ the\ operator.* ]] || [[ $result =~ ^error\:\ api.*is\ updating$ ]]; then
59+
echo "retrying prediction..."
60+
$retry="true"
61+
break # skip request predictions from the remaining APIs and try again
62+
else
63+
echo "prediction failed"
64+
exit 1
65+
fi
66+
fi
67+
done
68+
69+
if [ "$retry" == "false" ]; then
70+
break # successfully got predictions from all APIs for this example, move into the next
71+
else
72+
retry="false"
73+
fi
74+
fi
75+
76+
timer=$((timer-15))
77+
echo "Running $example_base_dir. $timer seconds left before timing out."
78+
if [ $timer -lt "0" ]; then
79+
echo "timed out!"
80+
exit 1
81+
fi
82+
done
83+
84+
$CORTEX delete
85+
done
86+
87+
echo "Ran all examples successfully."

images/test/Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ FROM cortexlabs/spark
33
RUN pip3 install pytest mock
44

55
COPY pkg/workloads /src
6+
COPY pkg/aggregators /aggregators
7+
COPY pkg/transformers /transformers
8+
69
COPY images/test/run.sh /src/run.sh
710

811
WORKDIR /src

images/test/run.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@
1818
err=0
1919
trap 'err=1' ERR
2020

21-
cd spark_job
21+
cd lib
2222
pytest
2323
cd ..
2424

25-
cd lib
26-
pytest
25+
cd spark_job
26+
pytest test/unit
27+
pytest test/integration
2728
cd ..
2829

2930
test $err = 0

pkg/workloads/lib/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14+
15+
from .context import Context

pkg/workloads/lib/aws.py

Lines changed: 0 additions & 217 deletions
This file was deleted.

0 commit comments

Comments
 (0)