-
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.
#335 test: add finishAction performance test
- Loading branch information
1 parent
de1f8c5
commit 5fe013e
Showing
6 changed files
with
152 additions
and
39 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
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, 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) - (15000/10), // 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, "W", 1001, exercise => { | ||
patientId = exercise.areas[0].patients[0].patientId | ||
resolve() | ||
}) | ||
}) | ||
|
||
await new Promise(resolve => { | ||
socketTrainer.patientAdd(areaId, "W", 1001, 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("Turniquet", confirmed => { | ||
if (!confirmed) throw Error("action declined") | ||
}, () => 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
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,25 @@ | ||
import axios from "axios"; | ||
|
||
export async function connectTrainer(socketTrainer, trainerName) { | ||
const response = await axios.post(`http://localhost/api/trainer/login`, { | ||
username: trainerName, | ||
password: 'password123' | ||
}) | ||
const token = response.data.token; | ||
|
||
await new Promise(resolve => { | ||
socketTrainer.connect(token, () => resolve()) | ||
}) | ||
} | ||
|
||
export async function connectPatient(socketPatient, exerciseId, patientId) { | ||
const response = await axios.post(`http://localhost/api/patient/access`, { | ||
exerciseId: exerciseId, | ||
patientId: patientId, | ||
}) | ||
const token = response.data.token; | ||
|
||
await new Promise(resolve => { | ||
socketPatient.connect(token, () => resolve()) | ||
}) | ||
} |
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