Skip to content

Commit

Permalink
#335 test: adapt assignMaterial 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 c42a3dc commit 1cd4050
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 18 deletions.
2 changes: 1 addition & 1 deletion backend/dps_training_k/game/models/patient_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def apply_pretreatments(self):
def schedule_state_change(self, time_offset=0):
from game.models import ScheduledEvent

state_change_time = 30
state_change_time = 600

if self.patient_state.is_dead:
return False
Expand Down
67 changes: 51 additions & 16 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 = 50

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

Expand All @@ -16,25 +18,67 @@ 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_total = 0, responseTime_base = 0, responseTime_cv = 0

for (let i = 0; i < assignmentCycles; i++) {
let endTime_base, endTime_cv
let startTime = now();
const assignmentPromise1 = new Promise(resolve => {
socketPatient.assignMaterial(materialId, () => {
resolve()
endTime_base = now()
})
})
const continuousPromise1 = new Promise(resolve => {
socketPatient.addContinuousVariableCb(() => {
resolve()
endTime_cv = now()
})
})
await Promise.all([assignmentPromise1, continuousPromise1])
let endTime_total = now();
responseTime_total += (endTime_total - startTime)
responseTime_base += (endTime_base - startTime)
responseTime_cv += (endTime_cv - startTime)

startTime = now();
const assignmentPromise2 = new Promise(resolve => {
socketPatient.releaseMaterial(materialId, () => {
resolve()
endTime_base = now()
})
})
const continuousPromise2 = new Promise(resolve => {
socketPatient.addContinuousVariableCb(() => {
resolve()
endTime_cv = now()
})
})
await Promise.all([assignmentPromise2, continuousPromise2])
endTime_total = now();
responseTime_total += (endTime_total - startTime)
responseTime_base += (endTime_base - startTime)
responseTime_cv += (endTime_cv - startTime)
}
const endTime = now();


socketPatient.close()
socketTrainer.close()

parentPort.postMessage({
userIndex,
responseTime: (endTime - startTime) / 200,
responseTime_total: responseTime_total / (assignmentCycles*2),
responseTime_base: responseTime_base / (assignmentCycles*2),
responseTime_cv: responseTime_cv / (assignmentCycles*2),
success: true
});
parentPort.close()
} catch (error) {
parentPort.postMessage({
userIndex,
responseTime: 0,
responseTime_total: 0,
responseTime_base: 0,
responseTime_cv: 0,
success: false,
error: error.message
});
Expand All @@ -58,7 +102,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 +120,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);
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('./phaseChange.js', {
const worker = new Worker('./assignMaterial.js', {
workerData: { userIndex }
});

Expand Down

0 comments on commit 1cd4050

Please sign in to comment.