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 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
|
#!/bin/sh
set -e
TESTDIR="$(readlink -f "$(dirname "$0")")"
. "$TESTDIR/framework"
testsecondsgreaterequal() {
seconds="$1"
shift
before=$(date +%s)
"$@"
after=$(date +%s)
msggroup 'testsecondsgreaterequal'
msgtest "Checking that previous test took more than $secondss"
if [ $((after - before)) -lt $seconds ]; then
msgfail "Took $((after - before)) second"
else
msgpass
fi
msggroup
}
setupenvironment
configarchitecture 'amd64'
buildsimplenativepackage 'testpkg' 'all' '1' 'stable'
setupaptarchive --no-update
changetowebserver
testsuccess apt update
cd downloaded
testsuccess apt download testpkg
testsuccess test -f testpkg_1_all.deb
rm -f testpkg_1_all.deb
msgmsg 'Fail after too many retries'
webserverconfig 'aptwebserver::failrequest' '429'
webserverconfig 'aptwebserver::failrequest::pool/testpkg_1_all.deb' '99'
testsecondsgreaterequal 5 testfailureequal "Delaying http://localhost:${APTHTTPPORT} stable/main all testpkg all 1 by 1 seconds
Ign:1 http://localhost:${APTHTTPPORT} stable/main all testpkg all 1
429 Unknown HTTP code
Delaying http://localhost:${APTHTTPPORT} stable/main all testpkg all 1 by 2 seconds
Ign:1 http://localhost:${APTHTTPPORT} stable/main all testpkg all 1
429 Unknown HTTP code
Delaying http://localhost:${APTHTTPPORT} stable/main all testpkg all 1 by 4 seconds
Ign:1 http://localhost:${APTHTTPPORT} stable/main all testpkg all 1
429 Unknown HTTP code
Err:1 http://localhost:${APTHTTPPORT} stable/main all testpkg all 1
429 Unknown HTTP code
E: Failed to fetch http://localhost:${APTHTTPPORT}/pool/testpkg_1_all.deb 429 Unknown HTTP code" apt download testpkg -o acquire::retries=3 -o debug::acquire::retries=true -q -o Acquire::Progress::Ignore::ShowErrorText=true
testfailure test -f testpkg_1_all.deb
testsecondsgreaterequal 5 testfailureequal "Delaying http://localhost:${APTHTTPPORT} stable/main all testpkg all 1 by 1 seconds
Ign:1 http://localhost:${APTHTTPPORT} stable/main all testpkg all 1
Delaying http://localhost:${APTHTTPPORT} stable/main all testpkg all 1 by 2 seconds
Ign:1 http://localhost:${APTHTTPPORT} stable/main all testpkg all 1
Delaying http://localhost:${APTHTTPPORT} stable/main all testpkg all 1 by 4 seconds
Ign:1 http://localhost:${APTHTTPPORT} stable/main all testpkg all 1
Err:1 http://localhost:${APTHTTPPORT} stable/main all testpkg all 1
429 Unknown HTTP code
E: Failed to fetch http://localhost:${APTHTTPPORT}/pool/testpkg_1_all.deb 429 Unknown HTTP code" apt download testpkg -o acquire::retries=3 -o debug::acquire::retries=true -q -o Acquire::Progress::Ignore::ShowErrorText=false
testfailure test -f testpkg_1_all.deb
msgmsg 'Retry 429 TooManyRequests after Retry-After time'
webserverconfig 'aptwebserver::failrequest' '429'
webserverconfig 'aptwebserver::failrequest::retryafter' '5'
webserverconfig 'aptwebserver::failrequest::pool/testpkg_1_all.deb' '1'
testsecondsgreaterequal 5 testsuccess apt download testpkg -o acquire::retries=1 -o acquire::retries::handleretryafter=true -o debug::acquire::retries=true -q
webserverconfig 'aptwebserver::failrequest::retryafter' '0'
testsuccess test -f testpkg_1_all.deb
rm -f testpkg_1_all.deb
msgmsg 'Success in the third try'
webserverconfig 'aptwebserver::failrequest::pool/testpkg_1_all.deb' '2'
testsuccess apt download testpkg -o acquire::retries=3 -o acquire::retries::delay=false
testsuccess test -f testpkg_1_all.deb
rm -f testpkg_1_all.deb
msgmsg 'Hard failure after retry request'
webserverconfig 'aptwebserver::failrequest::pool/unavailable_1_all.deb' '1'
testfailureequal "Ign:1 http://localhost:${APTHTTPPORT}/pool/unavailable_1_all.deb
429 Unknown HTTP code
Err:1 http://localhost:${APTHTTPPORT}/pool/unavailable_1_all.deb
404 Not Found
E: Failed to fetch http://localhost:${APTHTTPPORT}/pool/unavailable_1_all.deb 404 Not Found
E: Download Failed" apthelper download-file "http://localhost:${APTHTTPPORT}/pool/unavailable_1_all.deb" 'unavailable_1_all.deb' -o acquire::retries=2 -o acquire::retries::delay=false -o Acquire::Progress::Ignore::ShowErrorText=true
testfailure test -f unavailable_1_all.deb
webserverconfig 'aptwebserver::failrequest::pool/unavailable_1_all.deb' '1'
testfailureequal "Ign:1 http://localhost:${APTHTTPPORT}/pool/unavailable_1_all.deb
Err:1 http://localhost:${APTHTTPPORT}/pool/unavailable_1_all.deb
429 Unknown HTTP code
404 Not Found
E: Failed to fetch http://localhost:${APTHTTPPORT}/pool/unavailable_1_all.deb 404 Not Found
E: Download Failed" apthelper download-file "http://localhost:${APTHTTPPORT}/pool/unavailable_1_all.deb" 'unavailable_1_all.deb' -o acquire::retries=2 -o acquire::retries::delay=false -o Acquire::Progress::Ignore::ShowErrorText=false
testfailure test -f unavailable_1_all.deb
msgmsg 'Do not try everything again, hard failures keep hard failures'
webserverconfig 'aptwebserver::failrequest' '404'
webserverconfig 'aptwebserver::failrequest::pool/testpkg_1_all.deb' '2'
testfailure apt download testpkg -o acquire::retries=3
testfailure test -f testpkg_1_all.deb
cat ../rootdir/etc/apt/sources.list.d/apt-test-*.list > ../rootdir/etc/apt/sources.list.d/00http-source.list
changetohttpswebserver
msgmsg 'Check download from alternative sources if first failed'
webserverconfig 'aptwebserver::failrequest::pool/testpkg_1_all.deb' '0'
testsuccess apt update
testsuccess apt download testpkg -o acquire::retries=0
testsuccess test -f testpkg_1_all.deb
rm -f testpkg_1_all.deb
# we make the first source fail by disabling http support
webserverconfig 'aptwebserver::support::http' 'false'
testsuccess apt download testpkg -o acquire::retries=0
cp ../rootdir/tmp/testsuccess.output alt.output
testsuccess grep '^ 400 Bad Request' alt.output
testsuccess test -f testpkg_1_all.deb
rm -f testpkg_1_all.deb
|