2020-12-11 19:11:14 +00:00
|
|
|
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-11 19:11:14 +00:00
|
|
|
|
2020-12-15 23:03:44 +00:00
|
|
|
let data = JSON.parse(open('service.json'));
|
2020-12-11 19:11:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
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));
|
2020-12-11 19:11:14 +00:00
|
|
|
if (
|
2020-12-15 23:03:44 +00:00
|
|
|
!check(kvres, {
|
|
|
|
'kv status code MUST be 200': (kvres) => kvres.status == 200,
|
2020-12-11 19:11:14 +00:00
|
|
|
})
|
|
|
|
) {
|
2020-12-15 23:03:44 +00:00
|
|
|
fail(`registry check status code was *not* 200. error: ${kvres.error}. body: ${kvres.body}`)
|
2020-12-11 19:11:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//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));
|
2020-12-11 19:11:14 +00:00
|
|
|
if (
|
2020-12-15 23:03:44 +00:00
|
|
|
!check(servres, {
|
|
|
|
'register service status code MUST be 200': (servres) => servres.status == 200,
|
2020-12-11 19:11:14 +00:00
|
|
|
})
|
|
|
|
) {
|
2020-12-15 23:03:44 +00:00
|
|
|
fail(`registry check status code was *not* 200. error: ${servres.error}. body: ${servres.body}`)
|
2020-12-11 19:11:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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 2s
|
|
|
|
thresholds: { http_req_duration: ["p(95)<2000"] },
|
2020-12-11 19:11:14 +00:00
|
|
|
};
|