-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
73 lines (63 loc) · 1.99 KB
/
Copy pathscript.js
File metadata and controls
73 lines (63 loc) · 1.99 KB
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
73
import http from 'k6/http';
import { sleep } from 'k6';
import { htmlReport } from "https://raw.githubusercontent.com/benc-uk/k6-reporter/main/dist/bundle.js";
export const options = {
thresholds: {
http_req_duration: ["p(95)<1000"]
},
// A number specifying the number of VUs to run concurrently.
vus: 50,
// A string specifying the total duration of the test run.
duration: '600s',
};
// Function to generate a random MAC address
function generateRandomMacAddress() {
const characters = 'ABCDEF0123456789';
let macAddress = '';
for (let i = 0; i < 12; i++) {
macAddress += characters.charAt(Math.floor(Math.random() * characters.length));
if (i % 2 === 1 && i < 11) {
macAddress += ':';
}
}
return macAddress;
}
// Function to generate a random integer between min and max (inclusive)
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1) + min);
}
// Function to generate a random object with macAddress, type, and rssi
function generateRandomObject() {
return {
macAddress: generateRandomMacAddress(),
type: getRandomInt(0, 1),
rssi: getRandomInt(-100, 0)
};
}
// Number of objects you want in the array
const numberOfObjects = 100; // Change this as needed
// 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() {
// Generate the final object with trackerId and the array of objects
let requestBody = {
trackerId: getRandomInt(1, 100),
measurements: Array.from({ length: numberOfObjects }, generateRandomObject)
};
let res = http.post('http://10.0.0.1:8081/measurements/add', JSON.stringify(requestBody),{headers: { 'Content-Type': 'application/json' }});
if(res == null) {
console.log("No Response");
}
else{
console.log(res.json());
}
sleep(30);
}
export function handleSummary(data) {
return {
"summary.html": htmlReport(data),
};
}