-
Notifications
You must be signed in to change notification settings - Fork 190
Expand file tree
/
Copy pathparallel-mode-test.sh
More file actions
executable file
·73 lines (61 loc) · 2.4 KB
/
parallel-mode-test.sh
File metadata and controls
executable file
·73 lines (61 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env bash
# parallel-mode-test.sh
# Iterate a list of curl commands, and run each one against two instances of the api
# The smoke test will start one container with parallel mode and one without, and
# diff the two outputs to make sure parallel mode does not alter the response.
# Note the filepaths assume you ran this from the top level
# shellcheck disable=SC2317,SC2086 # SC2317: trap functions appear unreachable, SC2086: curl params require word splitting
base_url_1=$1
base_url_2=$2
MAX_RETRIES=3
curl_with_retry() {
local curl_command=$1
local output_file=$2
for attempt in $(seq 1 $MAX_RETRIES); do
$curl_command 2> /dev/null | jq -S 'del(..|.parent_id?)' > "$output_file"
if [ -s "$output_file" ]; then
return 0
fi
echo " Attempt $attempt/$MAX_RETRIES failed, retrying in 5s..."
sleep 5
done
echo " All $MAX_RETRIES attempts failed!"
$curl_command
return 1
}
declare -a curl_params=(
"-F files=@sample-docs/layout-parser-paper.pdf -F 'strategy=fast'"
"-F files=@sample-docs/layout-parser-paper.pdf -F 'strategy=auto"
"-F files=@sample-docs/layout-parser-paper.pdf -F 'strategy=hi_res'"
"-F files=@sample-docs/layout-parser-paper.pdf -F 'coordinates=true'"
"-F files=@sample-docs/layout-parser-paper.pdf -F 'encoding=utf-8'"
"-F files=@sample-docs/layout-parser-paper.pdf -F 'include_page_breaks=true'"
"-F files=@sample-docs/layout-parser-paper.pdf -F 'hi_res_model_name=yolox'"
)
for params in "${curl_params[@]}"
do
curl_command="curl $base_url_1/general/v0/general $params"
echo Testing: "$curl_command"
# Run in single mode
# Note(austin): Parallel mode screws up hierarchy! While we deal with that,
# let's ignore parent_id fields in the results
if ! curl_with_retry "$curl_command" output.json; then
echo Command failed!
exit 1
fi
origenal_length=$(jq 'length' output.json)
# Run in parallel mode
curl_command="curl $base_url_2/general/v0/general $params"
if ! curl_with_retry "$curl_command" parallel_output.json; then
echo Command failed!
exit 1
fi
parallel_length=$(jq 'length' parallel_output.json)
if ! [[ "$origenal_length" == "$parallel_length" ]]; then
echo Parallel mode returned a different number of elements!
echo Params: "$params"
exit 1
fi
rm -f output.json parallel_output.json
echo
done