Skip to content

Commit

Permalink
#335 test: adapt phaseChange 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 6f27359 commit c42a3dc
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions testing/backend-stress/src/phaseChange.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,46 @@ async function simulate(userIndex) {
})
})

let responseTime = 0
let responseTime_total = 0, responseTime_base = 0, responseTime_cv = 0
for (let i = 0; i < 5; i++) {
let endTime_base, endTime_cv
let startTime = now();
await new Promise(resolve => {
const statePromise = new Promise(resolve => {
socketPatient.addStateCb(() => {
resolve()
endTime_base = now()
})
})
let endTime = now();
responseTime += (endTime - startTime) - phaseLength
const continuousPromise = new Promise(resolve => {
socketPatient.addContinuousVariableCb(() => {
resolve()
endTime_cv = now()
})
})
await Promise.all([statePromise, continuousPromise])
let endTime_total = now();
responseTime_total += (endTime_total - startTime) - phaseLength
responseTime_base += (endTime_base - startTime) - phaseLength
responseTime_cv += (endTime_cv - startTime) - phaseLength
}

socketPatient.close()
socketTrainer.close()

parentPort.postMessage({
userIndex,
responseTime: responseTime / 5,
responseTime_total: responseTime_total / 5,
responseTime_base: responseTime_base / 5,
responseTime_cv: responseTime_cv / 5,
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 Down

0 comments on commit c42a3dc

Please sign in to comment.