Skip to content

Commit 0a4f3e7

Browse files
committed
updates to script
1 parent 37cb00e commit 0a4f3e7

File tree

2 files changed

+25
-11
lines changed

2 files changed

+25
-11
lines changed

load-test/scripts/configuration.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ export const MiniAppType = {
3434

3535
export function getTestOptions(maxUserGoal, rampUpTimeMinutes, highLoadTimeMinutes) {
3636
const maxConcurrentUsers = Math.floor(maxUserGoal / 30);
37+
// set constant VUs to be slightly higher than max concurrent users to account for users taking slightly different
38+
// amounts of time
39+
const constantVUs = Math.floor(maxUserGoal / 25);
3740
return {
3841
scenarios: {
3942
// ramp up to maxConcurrentUsers VUs over rampUpTimeMinutes
@@ -44,15 +47,16 @@ export function getTestOptions(maxUserGoal, rampUpTimeMinutes, highLoadTimeMinut
4447
{duration: `${rampUpTimeMinutes}m`, target: maxConcurrentUsers}
4548
]
4649
},
47-
// have maxConcurrentUsers VUs do 3 iterations each minute, for a total of highLoadTimeMinutes * 3
50+
// have constantVUs VUs do 3 iterations each minute, for a total of highLoadTimeMinutes * 3
4851
// iterations per virutal user.
4952
// Start this after the ramp up time and allow for 1 extra minute in the max duration in case of issues.
5053
highLoad: {
5154
executor: "per-vu-iterations",
52-
vus: maxConcurrentUsers,
55+
vus: constantVUs,
5356
iterations: 3 * highLoadTimeMinutes, // this is iterations per virtual user
54-
maxDuration: `${highLoadTimeMinutes + 1}m`,
55-
startTime: `${rampUpTimeMinutes + 1}m`,
57+
// add a large buffer to max duration to ensure all requests can complete.
58+
maxDuration: `${highLoadTimeMinutes + (Math.floor(highLoadTimeMinutes * 0.5))}m`,
59+
startTime: `${rampUpTimeMinutes}m`,
5660
}
5761
},
5862
thresholds: {

load-test/scripts/loadTest.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ import generateToken from "./generateToken.js";
1818
// Change these options to increase the user goal or time to run the test.
1919
export const options = getTestOptions(
2020
/* User goal */ 100,
21-
/* Ramp up time minutes */ 2,
22-
/* High load time minutes */ 5
21+
/* Ramp up time minutes */ 1,
22+
/* High load time minutes */ 1
2323
);
2424

2525
// Change this to test different code
@@ -36,20 +36,28 @@ const longWebsocketSessions = new Counter("long_websocket_sessions");
3636
// websocket sessions > EXTRA_LONG_REQUEST_MS
3737
const extraLongWebsocketSessions = new Counter("extra_long_websocket_sessions");
3838

39+
40+
function isResultSuccess(result) {
41+
return result && result.status === 200;
42+
}
43+
3944
export default function () {
4045
const authToken = generateToken(MiniAppType.CONSOLE);
4146
const uploadResult = http.put(
4247
UPLOAD_URL + authToken,
4348
sourceToTest,
4449
UPLOAD_PARAMS
4550
);
46-
const res = ws.connect(WEBSOCKET_URL + authToken, WEBSOCKET_PARAMS, (socket) =>
47-
onSocketConnect(socket, Date.now())
48-
);
4951

50-
check(res, { "websocket status is 101": (r) => r && r.status === 101 });
52+
check(uploadResult, { "upload status is 200": (r) => isResultSuccess(r)});
53+
54+
if (isResultSuccess(uploadResult)) {
55+
const res = ws.connect(WEBSOCKET_URL + authToken, WEBSOCKET_PARAMS, (socket) =>
56+
onSocketConnect(socket, Date.now())
57+
);
5158

52-
check(uploadResult, { "upload status is 200": (r) => r && r.status === 200 });
59+
check(res, { "websocket status is 101": (r) => r && r.status === 101 });
60+
}
5361
}
5462

5563
function onSocketConnect(socket, startTime) {
@@ -58,6 +66,7 @@ function onSocketConnect(socket, startTime) {
5866
socket.on("message", function (data) {
5967
const parsedData = JSON.parse(data);
6068
if (parsedData.type === "EXCEPTION") {
69+
console.log("[EXCEPTION] " + parsedData.value);
6170
exceptionCounter.add(1);
6271
}
6372
});
@@ -78,6 +87,7 @@ function onSocketConnect(socket, startTime) {
7887
});
7988

8089
socket.on("error", function (e) {
90+
console.log("[ERROR] " + e.error());
8191
errorCounter.add(1);
8292
});
8393
}

0 commit comments

Comments
 (0)