load-test.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 res = http.post('http://localhost/echo.php', payload)
  57. check(res, {
  58. 'is status 200': (r) => r.status === 200,
  59. 'is echoed': (r) => r.body === payload
  60. })
  61. }