Last active
February 29, 2024 06:29
-
-
Save lovelock/c1f2ca18c2e7402f8f5841eb1cc24f4f to your computer and use it in GitHub Desktop.
k6 scripts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import http from 'k6/http'; | |
import { sleep } from 'k6'; | |
export const options = { | |
// A number specifying the number of VUs to run concurrently. | |
vus: 6, | |
// A string specifying the total duration of the test run. | |
duration: '10s', | |
summaryTrendStats: ['avg','min','med','max','p(90)','p(95)','p(99)','p(99.9)','p(99.99)'], | |
// The following section contains configuration options for execution of this | |
// test script in Grafana Cloud. | |
// | |
// See https://grafana.com/docs/grafana-cloud/k6/get-started/run-cloud-tests-from-the-cli/ | |
// to learn about authoring and running k6 test scripts in Grafana k6 Cloud. | |
// | |
// ext: { | |
// loadimpact: { | |
// // The ID of the project to which the test is assigned in the k6 Cloud UI. | |
// // By default tests are executed in default project. | |
// projectID: "", | |
// // The name of the test in the k6 Cloud UI. | |
// // Test runs with the same name will be grouped. | |
// name: "script.js" | |
// } | |
// }, | |
// Uncomment this section to enable the use of Browser API in your tests. | |
// | |
// See https://grafana.com/docs/k6/latest/using-k6-browser/running-browser-tests/ to learn more | |
// about using Browser API in your test scripts. | |
// | |
// scenarios: { | |
// // The scenario name appears in the result summary, tags, and so on. | |
// // You can give the scenario any name, as long as each name in the script is unique. | |
// ui: { | |
// // Executor is a mandatory parameter for browser-based tests. | |
// // Shared iterations in this case tells k6 to reuse VUs to execute iterations. | |
// // | |
// // See https://grafana.com/docs/k6/latest/using-k6/scenarios/executors/ for other executor types. | |
// executor: 'shared-iterations', | |
// options: { | |
// browser: { | |
// // This is a mandatory parameter that instructs k6 to launch and | |
// // connect to a chromium-based browser, and use it to run UI-based | |
// // tests. | |
// type: 'chromium', | |
// }, | |
// }, | |
// }, | |
// } | |
}; | |
// The function that defines VU logic. | |
// | |
// See https://grafana.com/docs/k6/latest/examples/get-started-with-k6/ to learn more | |
// about authoring k6 scripts. | |
// | |
export default function() { | |
const url = 'http://127.0.0.1:8080/foo'; | |
const payload = JSON.stringify({ | |
a: 'some thing to transport', | |
}); | |
const params = { | |
headers: { | |
'Content-Type': 'application/json', | |
}, | |
}; | |
http.post(url, payload, params); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
K6 is by far the best load testing tool I've ever met. Take this if you want more summary trend stats.