Newer
Older
dub_jkp / test / fetchzip.sh
  1. #!/usr/bin/env bash
  2. DIR=$(dirname "${BASH_SOURCE[0]}")
  3.  
  4. . "$DIR"/common.sh
  5.  
  6. PORT=$(getRandomPort)
  7.  
  8. ${DUB} remove gitcompatibledubpackage --non-interactive 2>/dev/null || true
  9.  
  10. ${DUB} build --single "$DIR"/test_registry.d
  11. "$DIR"/test_registry --folder="$DIR/issue1336-registry" --port=$PORT &
  12. PID=$!
  13. sleep 1
  14. trap 'kill $PID 2>/dev/null || true' exit
  15.  
  16. echo "Trying to download gitcompatibledubpackage (1.0.4)"
  17. timeout 1s ${DUB} fetch gitcompatibledubpackage@1.0.4 --skip-registry=all --registry=http://localhost:$PORT
  18. if [ $? -eq 124 ]; then
  19. die $LINENO 'Fetching from responsive registry should not time-out.'
  20. fi
  21. ${DUB} remove gitcompatibledubpackage@1.0.4
  22.  
  23. echo "Downloads should be retried when the zip is corrupted - gitcompatibledubpackage (1.0.3)"
  24. zipOut=$(! timeout 1s ${DUB} fetch gitcompatibledubpackage@1.0.3 --skip-registry=all --registry=http://localhost:$PORT 2>&1)
  25. rc=$?
  26.  
  27. if ! zipCount=$(grep -Fc 'Failed to extract zip archive' <<<"$zipOut") || [ "$zipCount" -lt 3 ] ; then
  28. echo '========== +Output was ==========' >&2
  29. echo "$zipOut" >&2
  30. echo '========== -Output was ==========' >&2
  31. die $LINENO 'DUB should have tried to download the zip archive multiple times.'
  32. elif [ $rc -eq 124 ]; then
  33. die $LINENO 'DUB timed out unexpectedly.'
  34. fi
  35. if ${DUB} remove gitcompatibledubpackage --non-interactive 2>/dev/null; then
  36. die $LINENO 'DUB should not have installed a broken package.'
  37. fi
  38.  
  39. echo "HTTP status errors on downloads should be retried - gitcompatibledubpackage (1.0.2)"
  40. retryOut=$(! timeout 1s ${DUB} fetch gitcompatibledubpackage@1.0.2 --skip-registry=all --registry=http://localhost:$PORT --vverbose 2>&1)
  41. rc=$?
  42. if ! retryCount=$(echo "$retryOut" | grep -Fc 'Bad Gateway') || [ "$retryCount" -lt 3 ] ; then
  43. echo '========== +Output was ==========' >&2
  44. echo "$retryOut" >&2
  45. echo '========== -Output was ==========' >&2
  46. die $LINENO "DUB should have retried download on server error multiple times, but only tried $retryCount times."
  47. elif [ $rc -eq 124 ]; then
  48. die $LINENO 'DUB timed out unexpectedly.'
  49. fi
  50. if ${DUB} remove gitcompatibledubpackage --non-interactive 2>/dev/null; then
  51. die $LINENO 'DUB should not have installed a package.'
  52. fi
  53.  
  54. echo "HTTP status errors on downloads should retry with fallback mirror - gitcompatibledubpackage (1.0.2)"
  55. timeout 1s "$DUB" fetch gitcompatibledubpackage@1.0.2 --skip-registry=all --registry="http://localhost:$PORT http://localhost:$PORT/fallback"
  56. if [ $? -eq 124 ]; then
  57. die $LINENO 'Fetching from responsive registry should not time-out.'
  58. fi
  59. ${DUB} remove gitcompatibledubpackage@1.0.2