Skip to content

Commit

Permalink
#335 test: adapt assignMaterial test to the updated assignMaterial te…
Browse files Browse the repository at this point in the history
…st in the 330 version
  • Loading branch information
Wolkenfarmer committed Oct 16, 2024
1 parent 9025961 commit a031b0c
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions testing/backend-stress/src/assignMaterial.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const socketTrainer = new SocketTrainer('http://localhost/ws/trainer/?token=')
const socketPatient = new SocketPatient('http://localhost/ws/patient/?token=')
let exerciseId, areaId, patientId, materialId

const assignmentCycles = 5

async function simulate(userIndex) {
const trainerName = `testuser${crypto.randomUUID()}`

Expand All @@ -16,18 +18,30 @@ async function simulate(userIndex) {
await prepareExercise()
await connectPatient(socketPatient, exerciseId, patientId)

const startTime = now();
for (let i = 0; i < 100; i++) {
await assignMaterial()
let responseTime = 0

for (let i = 0; i < assignmentCycles; i++) {
let startTime = now();
await new Promise(resolve => {
socketPatient.assignMaterial(materialId, () => resolve())
})
let endTime = now();
responseTime += (endTime - startTime)

startTime = now();
await new Promise(resolve => {
socketPatient.releaseMaterial(materialId, () => resolve())
})
endTime = now();
responseTime += (endTime - startTime)
}
const endTime = now();

socketPatient.close()
socketTrainer.close()

parentPort.postMessage({
userIndex,
responseTime: (endTime - startTime) / 200,
responseTime: responseTime / (assignmentCycles*2),
success: true
});
parentPort.close()
Expand Down Expand Up @@ -58,7 +72,7 @@ async function prepareExercise() {
})

await new Promise(resolve => {
socketTrainer.patientAdd(areaId, "", 1005, exercise => {
socketTrainer.patientAdd(areaId, "", 1001, exercise => {
patientId = exercise.areas[0].patients[0].patientId
resolve()
})
Expand All @@ -76,13 +90,4 @@ async function prepareExercise() {
})
}

async function assignMaterial() {
await new Promise(resolve => {
socketPatient.assignMaterial(materialId, () => resolve())
})
await new Promise(resolve => {
socketPatient.releaseMaterial(materialId, () => resolve())
})
}

simulate(workerData.userIndex);

0 comments on commit a031b0c

Please sign in to comment.