test-acquire-same-file-multiple-times 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #!/bin/sh
  2. set -e
  3. TESTDIR="$(readlink -f "$(dirname "$0")")"
  4. . "$TESTDIR/framework"
  5. setupenvironment
  6. configarchitecture 'amd64'
  7. TESTFILE="$TESTDIR/framework"
  8. cp "$TESTFILE" aptarchive/foo
  9. APTARCHIVE="$(readlink -f ./aptarchive)"
  10. filedown() {
  11. msgtest 'Downloading the same URI twice over file' "$1"
  12. testsuccess --nomsg apthelper download-file "file:///$APTARCHIVE/foo" './downloaded/foo1' '' \
  13. "file:///$APTARCHIVE/foo" './downloaded/foo2' '' -o Debug::pkgAcquire::Worker=1
  14. cp rootdir/tmp/testsuccess.output download.log
  15. testsuccess cmp "$TESTFILE" ./downloaded/foo1
  16. testsuccess cmp ./downloaded/foo1 ./downloaded/foo2
  17. testequal '1' grep -c '200%20URI%20Start' ./download.log
  18. testequal '1' grep -c '201%20URI%20Done' ./download.log
  19. rm -f ./downloaded/foo1 ./downloaded/foo2
  20. }
  21. testrun() {
  22. $1 'no partial'
  23. cp "$TESTFILE" ./downloaded/foo1
  24. $1 'complete partial 1'
  25. cp "$TESTFILE" ./downloaded/foo2
  26. $1 'complete partial 2'
  27. cp "$TESTFILE" ./downloaded/foo1
  28. cp "$TESTFILE" ./downloaded/foo2
  29. $1 'complete partial 1+2'
  30. dd if="$TESTFILE" of=./downloaded/foo1 bs=500 count=1 2>/dev/null
  31. $1 'partial partial 1'
  32. dd if="$TESTFILE" of=./downloaded/foo2 bs=500 count=1 2>/dev/null
  33. $1 'partial partial 2'
  34. dd if="$TESTFILE" of=./downloaded/foo1 bs=500 count=1 2>/dev/null
  35. dd if="$TESTFILE" of=./downloaded/foo2 bs=500 count=1 2>/dev/null
  36. $1 'partial partial 1+2'
  37. }
  38. testrun 'filedown'
  39. changetowebserver -o aptwebserver::redirect::replace::/foo2=/foo
  40. httpdown() {
  41. msgtest 'Downloading the same URI to different files' 'twice over http'
  42. testsuccess --nomsg apthelper download-file "http://localhost:${APTHTTPPORT}/foo" "./downloaded/foo1" '' \
  43. "http://localhost:${APTHTTPPORT}/foo" './downloaded/foo2' '' -o Debug::pkgAcquire::Worker=1 -o Debug::Acquire::http=1
  44. cp rootdir/tmp/testsuccess.output download.log
  45. testsuccess cmp "$TESTDIR/framework" ./downloaded/foo1
  46. testsuccess cmp ./downloaded/foo1 ./downloaded/foo2
  47. testequal '1' grep -c '200%20URI%20Start' ./download.log
  48. testequal '1' grep -c '201%20URI%20Done' ./download.log
  49. rm -f ./downloaded/foo1 ./downloaded/foo2
  50. }
  51. testrun 'httpdown'
  52. httpredirectdown() {
  53. msgtest 'Redirect leads' 'first URI to the second URI'
  54. for i in 1 2 3 4 5 6 7 8 9 10; do
  55. testsuccess --nomsg apthelper download-file "http://localhost:${APTHTTPPORT}/foo2" "./downloaded/foo1" '' \
  56. "http://localhost:${APTHTTPPORT}/foo" './downloaded/foo2' '' -o Debug::pkgAcquire::Worker=1 -o Debug::Acquire::http=1
  57. cp rootdir/tmp/testsuccess.output download.log
  58. testsuccess cmp "$TESTDIR/framework" ./downloaded/foo1
  59. testsuccess cmp ./downloaded/foo1 ./downloaded/foo2
  60. if grep -q '103%20Redirect' ./download.log; then
  61. break
  62. fi
  63. done
  64. testequal '1' grep -c '200%20URI%20Start' ./download.log
  65. testequal '1' grep -c '103%20Redirect' ./download.log
  66. testequal '1' grep -c '201%20URI%20Done' ./download.log
  67. rm -f ./downloaded/foo1 ./downloaded/foo2
  68. }
  69. testrun 'httpredirectdown'
  70. httpsamedown() {
  71. msgtest 'Downloading two files via the same URI to' 'the same file'
  72. testsuccess --nomsg apthelper download-file "http://localhost:${APTHTTPPORT}/foo" "./downloaded/foo1" '' \
  73. "http://localhost:${APTHTTPPORT}/foo" './downloaded/foo1' '' -o Debug::pkgAcquire::Worker=1
  74. cp rootdir/tmp/testsuccess.output download.log
  75. testsuccess cmp "$TESTDIR/framework" ./downloaded/foo1
  76. testequal '1' grep -c '200%20URI%20Start' ./download.log
  77. testequal '1' grep -c '201%20URI%20Done' ./download.log
  78. rm -f ./downloaded/foo1
  79. }
  80. testrun 'httpsamedown'