hanging-requests.js 722 B

12345678910111213141516171819202122232425262728
  1. import http from 'k6/http'
  2. /**
  3. * It is not uncommon for external services to hang for a long time.
  4. * Make sure the server is resilient in such cases and doesn't hang as well.
  5. */
  6. export const options = {
  7. stages: [
  8. { duration: '20s', target: 100 },
  9. { duration: '20s', target: 500 },
  10. { duration: '20s', target: 0 }
  11. ],
  12. thresholds: {
  13. http_req_failed: ['rate<0.01']
  14. }
  15. }
  16. /* global __ENV */
  17. export default function () {
  18. // 2% chance for a request that hangs for 15s
  19. if (Math.random() < 0.02) {
  20. http.get(`${__ENV.CADDY_HOSTNAME}/sleep.php?sleep=15000&work=10000&output=100`)
  21. return
  22. }
  23. // a regular request
  24. http.get(`${__ENV.CADDY_HOSTNAME}/sleep.php?sleep=5&work=10000&output=100`)
  25. }