timeouts.js 957 B

1234567891011121314151617181920212223242526272829303132
  1. import http from 'k6/http'
  2. /**
  3. * Databases or external resources can sometimes become unavailable for short periods of time.
  4. * Make sure the server can recover quickly from periods of unavailability.
  5. * This simulation swaps between a hanging and a working server every 10 seconds.
  6. */
  7. export const options = {
  8. stages: [
  9. { duration: '20s', target: 100 },
  10. { duration: '20s', target: 500 },
  11. { duration: '20s', target: 0 }
  12. ],
  13. thresholds: {
  14. http_req_failed: ['rate<0.01']
  15. }
  16. }
  17. /* global __ENV */
  18. export default function () {
  19. const tenSecondInterval = Math.floor(new Date().getSeconds() / 10)
  20. const shouldHang = tenSecondInterval % 2 === 0
  21. // every 10 seconds requests lead to a max_execution-timeout
  22. if (shouldHang) {
  23. http.get(`${__ENV.CADDY_HOSTNAME}/sleep.php?sleep=50000`)
  24. return
  25. }
  26. // every other 10 seconds the resource is back
  27. http.get(`${__ENV.CADDY_HOSTNAME}/sleep.php?sleep=5&work=30000&output=100`)
  28. }