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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. rm -f ./downloaded/foo1 ./downloaded/foo2
  56. testsuccess --nomsg apthelper download-file "http://localhost:${APTHTTPPORT}/foo2" "./downloaded/foo1" '' \
  57. "http://localhost:${APTHTTPPORT}/foo" './downloaded/foo2' '' -o Debug::pkgAcquire::Worker=1 -o Debug::Acquire::http=1
  58. cp rootdir/tmp/testsuccess.output download.log
  59. testsuccess cmp "$TESTDIR/framework" ./downloaded/foo1
  60. testsuccess cmp ./downloaded/foo1 ./downloaded/foo2
  61. if grep -q '103%20Redirect' ./download.log; then
  62. break
  63. fi
  64. done
  65. testequal '1' grep -c '200%20URI%20Start' ./download.log
  66. testequal '1' grep -c '103%20Redirect' ./download.log
  67. testequal '1' grep -c '201%20URI%20Done' ./download.log
  68. rm -f ./downloaded/foo1 ./downloaded/foo2
  69. }
  70. testrun 'httpredirectdown'
  71. httpsamedown() {
  72. msgtest 'Downloading two files via the same URI to' 'the same file'
  73. testsuccess --nomsg apthelper download-file "http://localhost:${APTHTTPPORT}/foo" "./downloaded/foo1" '' \
  74. "http://localhost:${APTHTTPPORT}/foo" './downloaded/foo1' '' -o Debug::pkgAcquire::Worker=1
  75. cp rootdir/tmp/testsuccess.output download.log
  76. testsuccess cmp "$TESTDIR/framework" ./downloaded/foo1
  77. testequal '1' grep -c '200%20URI%20Start' ./download.log
  78. testequal '1' grep -c '201%20URI%20Done' ./download.log
  79. rm -f ./downloaded/foo1
  80. }
  81. testrun 'httpsamedown'