test-apt-download-progress 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #!/bin/sh
  2. #
  3. # ensure downloading sends progress as a regression test for commit 9127d7ae
  4. #
  5. set -e
  6. TESTDIR="$(readlink -f "$(dirname "$0")")"
  7. . "$TESTDIR/framework"
  8. setupenvironment
  9. changetohttpswebserver
  10. assertprogress() {
  11. T="$1"
  12. testsuccess grep "dlstatus:1:0:Retrieving file 1 of 1" "$T"
  13. if ! grep -E -q "dlstatus:1:(0\..*|([1-9](\..*)?)|[1-9][0-9](\..*)?):Retrieving file 1 of 1" "$T"; then
  14. cat "$T"
  15. msgfail "Failed to detect download progress"
  16. fi
  17. testsuccess grep "dlstatus:1:100:Retrieving file 1 of 1" "$T"
  18. }
  19. # we need to ensure the file is reasonable big so that apt has a chance to
  20. # actually report progress - but not too big to ensure its not delaying the
  21. # test too much
  22. TESTFILE=testfile.big
  23. testsuccess dd if=/dev/zero of=./aptarchive/$TESTFILE bs=16000k count=1
  24. OPT='-o APT::Status-Fd=3 -o Debug::pkgAcquire::Worker=1 -o Debug::Acquire::http=1 -o Debug::Acquire::https=1'
  25. msgtest 'download progress works via' 'http'
  26. for i in 1 2 3 4 5 6 7 8 9 10; do
  27. exec 3> apt-progress-http.log
  28. testsuccess --nomsg apthelper download-file "http://localhost:${APTHTTPPORT}/$TESTFILE" ./downloaded/http-$TESTFILE $OPT -o Acquire::http::Dl-Limit=$((16000/i))
  29. if [ "$(wc -l apt-progress-http.log | awk '{print $1}')" -ge 3 ]; then
  30. break
  31. fi
  32. done
  33. assertprogress apt-progress-http.log
  34. msgtest 'download progress works via' 'https'
  35. for i in 1 2 3 4 5 6 7 8 9 10; do
  36. exec 3> apt-progress-https.log
  37. testsuccess --nomsg apthelper download-file "https://localhost:${APTHTTPSPORT}/$TESTFILE" ./downloaded/https-$TESTFILE $OPT -o Acquire::https::Dl-Limit=$((16000/i))
  38. if [ "$(wc -l apt-progress-https.log | awk '{print $1}')" -ge 3 ]; then
  39. break
  40. fi
  41. done
  42. assertprogress apt-progress-https.log
  43. # cleanup
  44. rm -f apt-progress*.log