Newer
Older
dub_jkp / test / timeout.sh
@Martin Nowak Martin Nowak on 27 Jan 2018 1 KB fix netcat-openbsd compatibility
  1. #!/usr/bin/env bash
  2.  
  3. . $(dirname "${BASH_SOURCE[0]}")/common.sh
  4.  
  5. PORT=$(($$ + 1024)) # PID + 1024
  6.  
  7. log ' Testing unconnectable registry'
  8. if timeout 1s $DUB fetch dub --skip-registry=all --registry=http://localhost:$PORT; then
  9. die 'Fetching from unconnectable registry should fail.'
  10. elif [ $? -eq 124 ]; then
  11. die 'Fetching from unconnectable registry should fail immediately.'
  12. fi
  13.  
  14. log ' Testing non-responding registry'
  15. cat | nc -l $PORT >/dev/null &
  16. PID=$!
  17. if timeout 10s $DUB fetch dub --skip-registry=all --registry=http://localhost:$PORT; then
  18. die 'Fetching from non-responding registry should fail.'
  19. elif [ $? -eq 124 ]; then
  20. die 'Fetching from non-responding registry should time-out within 8s.'
  21. fi
  22. kill $PID 2>/dev/null || true
  23.  
  24. log ' Testing too slow registry'
  25. {
  26. res=$(printf 'HTTP/1.1 200 OK\r
  27. Server: dummy\r
  28. Content-Type: application/json\r
  29. Content-Length: 2\r
  30. \r
  31. {}')
  32. for i in $(seq 0 $((${#res} - 1))); do
  33. echo -n "${res:$i:1}"
  34. sleep 1
  35. done
  36. } | nc -l $PORT >/dev/null &
  37. PID=$!
  38. if timeout 10s time $DUB fetch dub --skip-registry=all --registry=http://localhost:$PORT; then
  39. die 'Fetching from too slow registry should fail.'
  40. elif [ $? -eq 124 ]; then
  41. die 'Fetching from too slow registry should time-out within 8s.'
  42. fi
  43. kill $PID 2>/dev/null || true