index.js 875 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import { randomSeed } from 'k6';
  2. import http from 'k6/http';
  3. import { SharedArray } from 'k6/data';
  4. import exec from 'k6/execution';
  5. const URL_PREFIX = "http://localhost:8082/unsafe"
  6. export let options = {
  7. discardResponseBodies: true,
  8. noConnectionReuse: false,
  9. vus: 20,
  10. iterations: 10000,
  11. };
  12. randomSeed(42)
  13. const urls = new SharedArray('urls', function () {
  14. const data = JSON.parse(open('./urls.json'));
  15. let unshuffled = [];
  16. data.forEach((e) => {
  17. let url = URL_PREFIX + e.url
  18. let weight = e.weight || 1
  19. for (var i = 0; i < weight; i++) {
  20. unshuffled.push(url)
  21. }
  22. })
  23. let shuffled = unshuffled
  24. .map(value => ({ value, sort: Math.random() }))
  25. .sort((a, b) => a.sort - b.sort)
  26. .map(({ value }) => value)
  27. return shuffled;
  28. });
  29. export default function() {
  30. http.get(urls[exec.scenario.iterationInTest % urls.length])
  31. }