Skip to content

Commit

Permalink
#335 test: adapt finishAction test to include continuous variables
Browse files Browse the repository at this point in the history
  • Loading branch information
Wolkenfarmer committed Oct 16, 2024
1 parent 2de049b commit 93b81f3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
33 changes: 21 additions & 12 deletions testing/backend-stress/src/finishAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,34 @@ async function simulate(userIndex) {
socketPatient.assignPersonnel(personnelId, () => resolve())
})

let endTime_base, endTime_cv
const startTime = now();
await doAction()
const endTime = now();
const actionPromise = new Promise(resolve => {
socketPatient.actionAdd(actionName, confirmed => {
if (!confirmed) throw Error("action declined")
}, () => {
resolve()
endTime_base = now()
})
})
const continuousPromise = new Promise(resolve => {
socketPatient.addContinuousVariableCb(() => {
resolve()
endTime_cv = now()
})
})

await Promise.all([actionPromise, continuousPromise])
const endTime_total = now();

socketPatient.close()
socketTrainer.close()

parentPort.postMessage({
userIndex,
responseTime: (endTime - startTime) - actionTime, // subtract execution time of action
responseTime_total: (endTime_total - startTime) - actionTime, // subtract execution time of action
responseTime_base: (endTime_base - startTime) - actionTime, // subtract execution time of action
responseTime_cv: (endTime_cv - startTime) - actionTime, // subtract execution time of action
success: true
});
parentPort.close()
Expand Down Expand Up @@ -64,7 +81,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 @@ -82,12 +99,4 @@ async function prepareExercise() {
})
}

async function doAction() {
await new Promise(resolve => {
socketPatient.actionAdd(actionName, confirmed => {
if (!confirmed) throw Error("action declined")
}, () => resolve())
})
}

simulate(workerData.userIndex);
2 changes: 1 addition & 1 deletion testing/backend-stress/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ let workerCount = 0;

function startWorker(userIndex) {
return new Promise((resolve, reject) => {
const worker = new Worker('./assignMaterial.js', {
const worker = new Worker('./finishAction.js', {
workerData: { userIndex }
});

Expand Down

0 comments on commit 93b81f3

Please sign in to comment.