Skip to content

Commit 0bf4ad6

Browse files
committed
Dont destructure object
1 parent c93f6cd commit 0bf4ad6

File tree

1 file changed

+11
-19
lines changed

1 file changed

+11
-19
lines changed

load-test/scripts/scannerLoadTestMetrics.js

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
import { Counter, Trend } from "k6/metrics";
22

3-
const metrics = {
4-
responseTime: new Trend("response_time", true),
5-
notSent: new Counter("not_sent"),
6-
noResponse: new Counter("no_response")
7-
};
8-
const metricsData = {
9-
sentAt: null,
10-
respondedAt: null
11-
};
3+
const responseTime = new Trend("response_time", true);
4+
const notSent = new Counter("not_sent");
5+
const noResponse = new Counter("no_response");
6+
let sentAt, respondedAt;
127

138
function onMessage(socket, parsedData) {
149
if (parsedData.type === "SYSTEM_OUT" && parsedData.value === "What's your name?") {
@@ -17,24 +12,21 @@ function onMessage(socket, parsedData) {
1712
message: "Ben"
1813
});
1914
socket.send(message);
20-
metricData.sentAt = Date.now();
15+
sentAt = Date.now();
2116
}
2217

2318
if (parsedData.type === "SYSTEM_OUT" && parsedData.value === "Hello Ben!") {
24-
metricData.respondedAt = Date.now();
19+
respondedAt = Date.now();
2520
}
2621
}
2722

2823
function onClose() {
29-
const {responseTime, notSent, noResponse} = metrics;
30-
const {sentAt, respondedAt} = metricData;
31-
32-
if (!metricData.sentAt) {
33-
metrics.notSent.add(1);
34-
} else if (!metricData.respondedAt) {
35-
metrics.noResponse.add(1);
24+
if (!sentAt) {
25+
notSent.add(1);
26+
} else if (!respondedAt) {
27+
noResponse.add(1);
3628
} else {
37-
metrics.responseTime.add(respondedAt - sentAt);
29+
responseTime.add(respondedAt - sentAt);
3830
}
3931
}
4032

0 commit comments

Comments
 (0)