consul/test/load/packer/loadtest-ami/scripts/loadtest.js

54 lines
1.4 KiB
JavaScript
Raw Normal View History

/**
* Copyright (c) HashiCorp, Inc.
[COMPLIANCE] License changes (#18443) * Adding explicit MPL license for sub-package This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository. * Adding explicit MPL license for sub-package This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository. * Updating the license from MPL to Business Source License Going forward, this project will be licensed under the Business Source License v1.1. Please see our blog post for more details at <Blog URL>, FAQ at www.hashicorp.com/licensing-faq, and details of the license at www.hashicorp.com/bsl. * add missing license headers * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 --------- Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com>
2023-08-11 13:12:13 +00:00
* SPDX-License-Identifier: BUSL-1.1
*/
import http from 'k6/http';
import { uuidv4 } from "https://jslib.k6.io/k6-utils/1.0.0/index.js";
2020-12-15 23:03:44 +00:00
import { check, fail } from 'k6';
2020-12-15 23:03:44 +00:00
let data = JSON.parse(open('service.json'));
export default function() {
const key = uuidv4();
const ipaddress = `http://${__ENV.LB_ENDPOINT}:8500`;
const kv_uri = '/v1/kv/';
const value = { data: uuidv4() };
const kv_address = `${ipaddress + kv_uri + key}`
//Put valid K/V
2020-12-15 23:03:44 +00:00
let kvres = http.put(kv_address, JSON.stringify(value));
if (
2020-12-15 23:03:44 +00:00
!check(kvres, {
'kv status code MUST be 200': (kvres) => kvres.status == 200,
})
) {
2020-12-15 23:03:44 +00:00
fail(`registry check status code was *not* 200. error: ${kvres.error}. body: ${kvres.body}`)
}
//Register Service
data["Name"] = key;
const service_uri = '/v1/agent/service/register';
2020-12-15 23:03:44 +00:00
const service_address = `${ipaddress + service_uri }`
let servres = http.put(service_address, JSON.stringify(data));
if (
2020-12-15 23:03:44 +00:00
!check(servres, {
'register service status code MUST be 200': (servres) => servres.status == 200,
})
) {
2020-12-15 23:03:44 +00:00
fail(`registry check status code was *not* 200. error: ${servres.error}. body: ${servres.body}`)
}
}
export let options = {
2020-12-15 23:03:44 +00:00
// 25 virtual users
vus: 25,
// 10 minute
duration: "10m",
// 95% of requests must complete below 2.5s
thresholds: { http_req_duration: ["p(95)<2500"] },
};