Newer
Older
dub_jkp / test / fetchzip.sh
@Sebastian Wilzbach Sebastian Wilzbach on 15 Mar 2018 2 KB Fix #1412 - wait longer until Vibe.d has started
  1. #!/usr/bin/env bash
  2. DIR=$(dirname "${BASH_SOURCE[0]}")
  3.  
  4. . "$DIR"/common.sh
  5.  
  6. PORT=$(($$ + 1024)) # PID + 1024
  7.  
  8. dub remove gitcompatibledubpackage --non-interactive --version=* 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 --version=1.0.4 --skip-registry=all --registry=http://localhost:$PORT
  18. if [ $? -eq 124 ]; then
  19. die 'Fetching from responsive registry should not time-out.'
  20. fi
  21. dub remove gitcompatibledubpackage --non-interactive --version=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 --version=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 'DUB should have tried to download the zip archive multiple times.'
  32. elif [ $rc -eq 124 ]; then
  33. die 'DUB timed out unexpectedly.'
  34. fi
  35. if dub remove gitcompatibledubpackage --non-interactive --version=* 2>/dev/null; then
  36. die '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 --version=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 "DUB should have retried download on server error multiple times, but only tried $retryCount times."
  47. elif [ $rc -eq 124 ]; then
  48. die 'DUB timed out unexpectedly.'
  49. fi
  50. if dub remove gitcompatibledubpackage --non-interactive --version=* 2>/dev/null; then
  51. die '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 --version=1.0.2 --skip-registry=all --registry="http://localhost:$PORT http://localhost:$PORT/fallback"
  56. if [ $? -eq 124 ]; then
  57. die 'Fetching from responsive registry should not time-out.'
  58. fi
  59. dub remove gitcompatibledubpackage --non-interactive --version=1.0.2