-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '335-add-performance-tests-for-front-and-backend-to-eval…
…uate-330' into 335-add-performance-tests-for-front-and-backend-to-evaluate-330-2
- Loading branch information
Showing
12 changed files
with
1,032 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"name": "backend-stress", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"build": "tsc" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"type": "module", | ||
"dependencies": { | ||
"axios": "^1.7.7", | ||
"performance-now": "^2.1.0", | ||
"ws": "^8.18.0" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^22.7.4", | ||
"@types/ws": "^8.5.12", | ||
"typescript": "^5.6.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import { parentPort, workerData } from "worker_threads"; | ||
import now from "performance-now"; | ||
import {SocketTrainer} from "./sockets/SocketTrainer.js" | ||
import {SocketPatient} from "./sockets/SocketPatient.js"; | ||
import {connectPatient, connectTrainer} from "./setupHelper.js"; | ||
|
||
const socketTrainer = new SocketTrainer('http://localhost/ws/trainer/?token=') | ||
const socketPatient = new SocketPatient('http://localhost/ws/patient/?token=') | ||
let exerciseId, areaId, patientId, materialId | ||
|
||
async function simulate(userIndex) { | ||
const trainerName = `testuser${crypto.randomUUID()}` | ||
|
||
try { | ||
await connectTrainer(socketTrainer, trainerName) | ||
await prepareExercise() | ||
await connectPatient(socketPatient, exerciseId, patientId) | ||
|
||
const startTime = now(); | ||
for (let i = 0; i < 100; i++) { | ||
await assignMaterial() | ||
} | ||
const endTime = now(); | ||
|
||
socketPatient.close() | ||
socketTrainer.close() | ||
|
||
parentPort.postMessage({ | ||
userIndex, | ||
responseTime: (endTime - startTime) / 200, | ||
success: true | ||
}); | ||
parentPort.close() | ||
} catch (error) { | ||
parentPort.postMessage({ | ||
userIndex, | ||
responseTime: now() - startTime, | ||
success: false, | ||
error: error.message | ||
}); | ||
} | ||
parentPort.close() | ||
} | ||
|
||
async function prepareExercise() { | ||
await new Promise(resolve => { | ||
socketTrainer.exerciseCreate(exercise => { | ||
exerciseId = exercise.exerciseId | ||
resolve() | ||
}) | ||
}) | ||
|
||
await new Promise(resolve => { | ||
socketTrainer.areaAdd(exercise => { | ||
areaId = exercise.areas[0].areaId | ||
resolve(true) | ||
}) | ||
}) | ||
|
||
await new Promise(resolve => { | ||
socketTrainer.patientAdd(areaId, "", 1005, exercise => { | ||
patientId = exercise.areas[0].patients[0].patientId | ||
resolve() | ||
}) | ||
}) | ||
|
||
await new Promise(resolve => { | ||
socketTrainer.materialAdd(areaId, "BZ-Messgerät", exercise => { | ||
materialId = exercise.areas[0].material[0].materialId | ||
resolve() | ||
}) | ||
}) | ||
|
||
await new Promise(resolve => { | ||
socketTrainer.exerciseStart(() => resolve()) | ||
}) | ||
} | ||
|
||
async function assignMaterial() { | ||
await new Promise(resolve => { | ||
socketPatient.assignMaterial(materialId, () => resolve()) | ||
}) | ||
await new Promise(resolve => { | ||
socketPatient.releaseMaterial(materialId, () => resolve()) | ||
}) | ||
} | ||
|
||
simulate(workerData.userIndex); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import {parentPort, workerData} from "worker_threads"; | ||
import now from "performance-now"; | ||
import {SocketTrainer} from "./sockets/SocketTrainer.js" | ||
import {SocketPatient} from "./sockets/SocketPatient.js"; | ||
import {connectPatient, connectTrainer} from "./setupHelper.js"; | ||
|
||
const actionName = "Turniquet" | ||
const actionTime = 15000 / 10 | ||
|
||
const socketTrainer = new SocketTrainer('http://localhost/ws/trainer/?token=') | ||
const socketPatient = new SocketPatient('http://localhost/ws/patient/?token=') | ||
let exerciseId, areaId, patientId, personnelId | ||
|
||
async function simulate(userIndex) { | ||
const trainerName = `testuser${crypto.randomUUID()}` | ||
|
||
try { | ||
await connectTrainer(socketTrainer, trainerName) | ||
await prepareExercise() | ||
await connectPatient(socketPatient, exerciseId, patientId) | ||
|
||
await new Promise(resolve => { | ||
socketPatient.assignPersonnel(personnelId, () => resolve()) | ||
}) | ||
|
||
const startTime = now(); | ||
await doAction() | ||
const endTime = now(); | ||
|
||
|
||
socketPatient.close() | ||
socketTrainer.close() | ||
|
||
parentPort.postMessage({ | ||
userIndex, | ||
responseTime: (endTime - startTime) - actionTime, // subtract execution time of action | ||
success: true | ||
}); | ||
parentPort.close() | ||
} catch (error) { | ||
parentPort.postMessage({ | ||
userIndex, | ||
responseTime: now() - startTime, | ||
success: false, | ||
error: error.message | ||
}); | ||
} | ||
parentPort.close() | ||
} | ||
|
||
async function prepareExercise() { | ||
await new Promise(resolve => { | ||
socketTrainer.exerciseCreate(exercise => { | ||
exerciseId = exercise.exerciseId | ||
resolve() | ||
}) | ||
}) | ||
|
||
await new Promise(resolve => { | ||
socketTrainer.areaAdd(exercise => { | ||
areaId = exercise.areas[0].areaId | ||
resolve(true) | ||
}) | ||
}) | ||
|
||
await new Promise(resolve => { | ||
socketTrainer.patientAdd(areaId, "", 1005, exercise => { | ||
patientId = exercise.areas[0].patients[0].patientId | ||
resolve() | ||
}) | ||
}) | ||
|
||
await new Promise(resolve => { | ||
socketTrainer.personnelAdd(areaId, "", exercise => { | ||
personnelId = exercise.areas[0].personnel[0].personnelId | ||
resolve() | ||
}) | ||
}) | ||
|
||
await new Promise(resolve => { | ||
socketTrainer.exerciseStart(() => resolve()) | ||
}) | ||
} | ||
|
||
async function doAction() { | ||
await new Promise(resolve => { | ||
socketPatient.actionAdd(actionName, confirmed => { | ||
if (!confirmed) throw Error("action declined") | ||
}, () => resolve()) | ||
}) | ||
} | ||
|
||
simulate(workerData.userIndex); |
Oops, something went wrong.