-
-
Notifications
You must be signed in to change notification settings - Fork 228
/
fetchzip.sh
executable file
·59 lines (50 loc) · 2.54 KB
/
fetchzip.sh
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
#!/usr/bin/env bash
DIR=$(dirname "${BASH_SOURCE[0]}")
. "$DIR"/common.sh
PORT=$(getRandomPort)
${DUB} remove gitcompatibledubpackage --non-interactive 2>/dev/null || true
${DUB} build --single "$DIR"/test_registry.d
"$DIR"/test_registry --folder="$DIR/issue1336-registry" --port=$PORT &
PID=$!
sleep 1
trap 'kill $PID 2>/dev/null || true' exit
echo "Trying to download gitcompatibledubpackage (1.0.4)"
timeout 1s ${DUB} fetch gitcompatibledubpackage@1.0.4 --skip-registry=all --registry=http://localhost:$PORT
if [ $? -eq 124 ]; then
die $LINENO 'Fetching from responsive registry should not time-out.'
fi
${DUB} remove gitcompatibledubpackage@1.0.4
echo "Downloads should be retried when the zip is corrupted - gitcompatibledubpackage (1.0.3)"
zipOut=$(! timeout 1s ${DUB} fetch gitcompatibledubpackage@1.0.3 --skip-registry=all --registry=http://localhost:$PORT 2>&1)
rc=$?
if ! zipCount=$(grep -Fc 'Failed to extract zip archive' <<<"$zipOut") || [ "$zipCount" -lt 3 ] ; then
echo '========== +Output was ==========' >&2
echo "$zipOut" >&2
echo '========== -Output was ==========' >&2
die $LINENO 'DUB should have tried to download the zip archive multiple times.'
elif [ $rc -eq 124 ]; then
die $LINENO 'DUB timed out unexpectedly.'
fi
if ${DUB} remove gitcompatibledubpackage --non-interactive 2>/dev/null; then
die $LINENO 'DUB should not have installed a broken package.'
fi
echo "HTTP status errors on downloads should be retried - gitcompatibledubpackage (1.0.2)"
retryOut=$(! timeout 1s ${DUB} fetch gitcompatibledubpackage@1.0.2 --skip-registry=all --registry=http://localhost:$PORT --vverbose 2>&1)
rc=$?
if ! retryCount=$(echo "$retryOut" | grep -Fc 'Bad Gateway') || [ "$retryCount" -lt 3 ] ; then
echo '========== +Output was ==========' >&2
echo "$retryOut" >&2
echo '========== -Output was ==========' >&2
die $LINENO "DUB should have retried download on server error multiple times, but only tried $retryCount times."
elif [ $rc -eq 124 ]; then
die $LINENO 'DUB timed out unexpectedly.'
fi
if ${DUB} remove gitcompatibledubpackage --non-interactive 2>/dev/null; then
die $LINENO 'DUB should not have installed a package.'
fi
echo "HTTP status errors on downloads should retry with fallback mirror - gitcompatibledubpackage (1.0.2)"
timeout 1s "$DUB" fetch gitcompatibledubpackage@1.0.2 --skip-registry=all --registry="http://localhost:$PORT http://localhost:$PORT/fallback"
if [ $? -eq 124 ]; then
die $LINENO 'Fetching from responsive registry should not time-out.'
fi
${DUB} remove gitcompatibledubpackage@1.0.2