-
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 basic concurrent trainer login and passthrough stress …
…test structure as separate node project
- Loading branch information
1 parent
a42890a
commit 7487011
Showing
7 changed files
with
1,633 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,23 @@ | ||
{ | ||
"name": "backend-stress", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"build": "tsc" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"type": "module", | ||
"dependencies": { | ||
"axios": "^1.7.7", | ||
"performance-now": "^2.1.0", | ||
"ws": "^8.18.0" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^22.7.4", | ||
"@types/ws": "^8.5.12", | ||
"typescript": "^5.6.2" | ||
} | ||
} |
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,44 @@ | ||
import { parentPort, workerData } from "worker_threads"; | ||
import axios from "axios"; | ||
import now from "performance-now"; | ||
import {SocketTrainer} from "./sockets/SocketTrainer.js" | ||
// import {NUM_TRAINER_PER_EXERCISE} from "./main.js"; | ||
|
||
async function simulateExercise(userIndex) { | ||
const trainerName = `testuser${crypto.randomUUID()}` | ||
|
||
const startTime = now(); | ||
|
||
try { | ||
const response = await axios.post(`https://klinik-dps.de/api/trainer/login`, { | ||
username: trainerName, | ||
password: 'password123' | ||
}); | ||
const token = response.data.token; | ||
|
||
const socketTrainer = new SocketTrainer('https://klinik-dps.de/ws/trainer/?token=') | ||
|
||
await new Promise(resolve => { | ||
socketTrainer.connect(token, response => resolve(response)); | ||
}); | ||
|
||
socketTrainer.testPassthrough((message) => {console.log(message)}) | ||
|
||
const endTime = now(); | ||
|
||
parentPort.postMessage({ | ||
userIndex, | ||
responseTime: endTime - startTime, | ||
success: true | ||
}); | ||
} catch (error) { | ||
parentPort.postMessage({ | ||
userIndex, | ||
responseTime: now() - startTime, | ||
success: false, | ||
error: error.message | ||
}); | ||
} | ||
} | ||
|
||
simulateExercise(workerData.userIndex); |
Oops, something went wrong.