Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'k6' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
functionNames.forEach(function (functionName) {
let url = `https://${functionName}.${__ENV.CLUSTER_DOMAIN_NAME}`
let tags = {
'testName': functionName,
}
let res = http.get(url, { 'tags': tags })
// report custom trend
// same as http_req_duration but without function execution time
httpReqDurationNoFunc.add(res.timings.duration - funcDelay);
// same as http_req_waiting but without function execution time
httpReqWaitingNoFunc.add(res.timings.waiting - funcDelay)
check(res, {
"status was 200": (r) => r.status == 200,
}, tags);
});
};
export default function (units) {
for (const lib of units) {
// k6 do not know how to store function in object yet
// https://github.com/loadimpact/k6/issues/855
// eslint-disable-next-line no-eval
group(lib.name, () => (lib.fn ? eval(lib.fn).default : test)(lib.setup))
}
}
import * as http from 'k6/http'
import { options as defaultOptions, prepare, assert } from './abstract-test.js'
export const options = Object.assign(defaultOptions, {
tlsVersion: {
min: http.SSL_3_0,
max: http.TLS_1_3
}
})
export function setup () {
return prepare([
{
name: 'intermediate policy',
requests: ['https://secure.server.localhost/']
}
])
}
export default function (data) {
assert(data, '', () => ({
'is TLS version secure': (r) => r.tls_version === http.TLS_1_2 || r.tls_version === http.TLS_1_3,
// 'is cipher suite secure': (r) => r.tls_cipher_suite === 'TLS_CHACHA20_POLY1305_SHA256',
'is TLS version secure': (r) => r.tls_version === http.TLS_1_2 || r.tls_version === http.TLS_1_3,
// 'is cipher suite secure': (r) => r.tls_cipher_suite === 'TLS_CHACHA20_POLY1305_SHA256',
import http from "k6/http"
import { check } from "k6"
import { Trend } from "k6/metrics"
var httpReqDurationNoFunc = new Trend("http_req_duration_no_func", true)
var httpReqWaitingNoFunc = new Trend("http_req_waiting_no_func", true)
export let options = {
// unlimited
rps: 0,
tags: {
"component": "serverless",
"revision": `${__ENV.REVISION}`
},
// ramp up #virtual users (VU) over time to get maximum throughput
stages: [
{ duration: "90s", target: 2 ** 3 },
{ duration: "90s", target: 2 ** 4 },
{ duration: "90s", target: 2 ** 5 },
],
}
import http from "k6/http"
import { check } from "k6"
import { Trend } from "k6/metrics"
var httpReqDurationNoFunc = new Trend("http_req_duration_no_func", true)
var httpReqWaitingNoFunc = new Trend("http_req_waiting_no_func", true)
export let options = {
// unlimited
rps: 0,
tags: {
"component": "serverless",
"revision": `${__ENV.REVISION}`
},
// ramp up #virtual users (VU) over time to get maximum throughput
stages: [
{ duration: "90s", target: 2 ** 3 },
{ duration: "90s", target: 2 ** 4 },
{ duration: "90s", target: 2 ** 5 },
],
}
export function teardown(){
// Cleanly shutdown and flush telemetry when k6 exits.
tracing.shutdown();
}
function makeGetRequest () {
const response = http.get(
// Have to limit transactions to 100 as request times out for all transactions
`${BASE_URL}/transactions?filterLimit=100`,
{
headers: Object.assign(getTestAuthHeaders(), {
Accept: 'application/json',
'Content-Type': 'apllication/json'
}),
tags: {
name: 'Transactions without filters'
}
}
)
check(response, {
'status code is 200': r => r.status === 200
})
const makePutRequest = () => {
// The id being created here should be unique, otherwise an update will actually happen
const id = `${Date.now() + Math.random()}`
patient.id = id
const response = http.put(`${BASE_URL}${RESOURCE_PATH}/${id}`,
JSON.stringify(patient),
{
headers: {
'Content-Type': 'application/json'
},
tags: {
name: `Patient Update-Create Stress Test`
}
})
check(response, {
'status code is 201': r => r.status === 201
})
}
export default function() {
const http = new Http({
exporter: "jaeger",
propagator: "w3c",
endpoint: "http://localhost:14268/api/traces"
});
const r = http.get('https://test-api.k6.io');
console.log(`trace-id=${r.trace_id}`);
sleep(1);
}