load-test.js 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import http from 'k6/http'
  2. import { check } from 'k6'
  3. export const options = {
  4. // A number specifying the number of VUs to run concurrently.
  5. vus: 100,
  6. // A string specifying the total duration of the test run.
  7. duration: '30s'
  8. // The following section contains configuration options for execution of this
  9. // test script in Grafana Cloud.
  10. //
  11. // See https://grafana.com/docs/grafana-cloud/k6/get-started/run-cloud-tests-from-the-cli/
  12. // to learn about authoring and running k6 test scripts in Grafana k6 Cloud.
  13. //
  14. // ext: {
  15. // loadimpact: {
  16. // // The ID of the project to which the test is assigned in the k6 Cloud UI.
  17. // // By default tests are executed in default project.
  18. // projectID: "",
  19. // // The name of the test in the k6 Cloud UI.
  20. // // Test runs with the same name will be grouped.
  21. // name: "script.js"
  22. // }
  23. // },
  24. // Uncomment this section to enable the use of Browser API in your tests.
  25. //
  26. // See https://grafana.com/docs/k6/latest/using-k6-browser/running-browser-tests/ to learn more
  27. // about using Browser API in your test scripts.
  28. //
  29. // scenarios: {
  30. // // The scenario name appears in the result summary, tags, and so on.
  31. // // You can give the scenario any name, as long as each name in the script is unique.
  32. // ui: {
  33. // // Executor is a mandatory parameter for browser-based tests.
  34. // // Shared iterations in this case tells k6 to reuse VUs to execute iterations.
  35. // //
  36. // // See https://grafana.com/docs/k6/latest/using-k6/scenarios/executors/ for other executor types.
  37. // executor: 'shared-iterations',
  38. // options: {
  39. // browser: {
  40. // // This is a mandatory parameter that instructs k6 to launch and
  41. // // connect to a Chromium-based browser, and use it to run UI-based
  42. // // tests.
  43. // type: 'chromium',
  44. // },
  45. // },
  46. // },
  47. // }
  48. }
  49. const payload = 'foo\n'.repeat(1000)
  50. // The function that defines VU logic.
  51. //
  52. // See https://grafana.com/docs/k6/latest/examples/get-started-with-k6/ to learn more
  53. // about authoring k6 scripts.
  54. //
  55. export default function () {
  56. const params = {
  57. headers: {
  58. Accept:
  59. 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8',
  60. // 'Accept-Encoding': 'br',
  61. 'Accept-Language': 'fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3',
  62. 'Cache-Control': 'no-cache',
  63. Connection: 'keep-alive',
  64. Cookie:
  65. 'user_session=myrandomuuid; __Host-user_session_same_site=myotherrandomuuid; dotcom_user=dunglas; logged_in=yes; _foo=barbarbarbarbarbar; _device_id=anotherrandomuuid; color_mode=foobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobar; preferred_color_mode=light; tz=Europe%2FParis; has_recent_activity=1',
  66. DNT: '1',
  67. Host: 'example.com',
  68. Pragma: 'no-cache',
  69. 'Sec-Fetch-Dest': 'document',
  70. 'Sec-Fetch-Mode': 'navigate',
  71. 'Sec-Fetch-Site': 'cross-site',
  72. 'Sec-GPC': '1',
  73. 'Upgrade-Insecure-Requests': '1',
  74. 'User-Agent':
  75. 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:122.0) Gecko/20100101 Firefox/122.0'
  76. }
  77. }
  78. const res = http.post('http://localhost/echo.php', payload, params)
  79. check(res, {
  80. 'is status 200': (r) => r.status === 200,
  81. 'is echoed': (r) => r.body === payload
  82. })
  83. }