-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathconstant-vus.js
72 lines (68 loc) · 2.71 KB
/
constant-vus.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import http from 'k6/http';
import { Kubernetes } from 'k6/x/kubernetes';
import * as deploy from "./common/common.js";
import { sleep } from 'k6';
const testScriptName = "constant-vus";
const replicas = `${__ENV.SK_REPLICAS}` != "undefined" ? parseInt(`${__ENV.SK_REPLICAS}`) : 1;
const namespace = `${__ENV.SK_NAMESPACE}` != "undefined" ? `${__ENV.SK_NAMESPACE}` : "default";
const executor = `${__ENV.SK_EXECUTOR}` != "undefined" ? `${__ENV.SK_EXECUTOR}` : "containerd-shim-spin";
const repo = `${__ENV.SK_OCI_REPO}` != "undefined" ? `${__ENV.SK_OCI_REPO}` : "ghcr.io/kate-goldenring/performance";
const tag = `${__ENV.SK_OCI_TAG}` != "undefined" ? `${__ENV.SK_OCI_TAG}` : "latest";
const route = `${__ENV.SK_SPIN_APP_ROUTE}` != "undefined" ? `${__ENV.SK_SPIN_APP_ROUTE}` : "";
const delay = `${__ENV.SK_DELAY}` != "undefined" ? `${__ENV.SK_DELAY}` : 0.1;
const appToTest = `${__ENV.SK_SPIN_APP}` != "undefined" ? `${__ENV.SK_SPIN_APP}` : "hello-world-rust";
const name = `${__ENV.SK_TEST_RUN_NAME}` != "undefined" ? `${__ENV.SK_TEST_RUN_NAME}` : testScriptName;
const testDuration='30s';
export let options = {
tags: {
test: testScriptName,
test_duration: testDuration,
},
thresholds: {
http_req_failed: ['rate<0.1'],
},
setupTimeout: '300s',
noConnectionReuse: true,
discardResponseBodies: true,
// executor: 'constant-vus', // this is the default executor and implied
vus: 20,
duration: testDuration,
};
/**
* Setup function that is executed before the test starts.
* It applies the SpinApp custom resource to the Kubernetes cluster.
* @returns {string} The URL to be used for the test.
*/
export function setup() {
console.log("Setting up test")
const kubernetes = new Kubernetes();
let image = deploy.imageForApp(repo, tag, appToTest);
deploy.applySpinApp(kubernetes, name, image, replicas, executor, namespace);
const timeout = 60;
if (deploy.waitAllAppsReady(kubernetes, timeout, namespace, replicas) === -1) {
console.error(`SpinApps not ready after ${timeout} seconds`);
return;
}
sleep(20);
return deploy.serviceEndpointForApp(name, namespace, route);
}
/**
* Main function that is executed during the test.
* It sends an HTTP GET request to the specified URL and performs a check on the response status.
* @param {string} data - The URL to send the request to.
*/
export default function (endpoint) {
http.get(endpoint, {tags: {
replicas: replicas,
}});
sleep(delay);
}
/**
* Teardown function that is executed after the test ends.
* It deletes the SpinApp custom resource from the Kubernetes cluster.
*/
export function teardown() {
console.log("Tearing down test")
const kubernetes = new Kubernetes();
kubernetes.delete("SpinApp.core.spinkube.dev", name, namespace);
}