Skip to content

Commit

Permalink
#335 test: add Timeout feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Wolkenfarmer committed Oct 16, 2024
1 parent 415e65e commit 6f27359
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
2 changes: 1 addition & 1 deletion testing/backend-stress/src/assignMaterial.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ async function simulate(userIndex) {
} catch (error) {
parentPort.postMessage({
userIndex,
responseTime: now() - startTime,
responseTime: 0,
success: false,
error: error.message
});
Expand Down
2 changes: 1 addition & 1 deletion testing/backend-stress/src/finishAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ async function simulate(userIndex) {
} catch (error) {
parentPort.postMessage({
userIndex,
responseTime: now() - startTime,
responseTime: 0,
success: false,
error: error.message
});
Expand Down
21 changes: 20 additions & 1 deletion testing/backend-stress/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,21 @@ function startWorker(userIndex) {
async function runStressTest() {
for (let i = 0; i < NUM_EXERCISES; i++) {
console.log("Processing iteration " + i)
await startWorker(i);
await Promise.race([
startWorker(i),
new Promise((_, reject) =>
setTimeout(() => reject(new Error('Timeout')), 60000)
)
])
.catch(() => {
results.push({
i,
responseTime_total: 0,
responseTime_base: 0,
responseTime_cv: 0,
success: false
})
});
}

console.log(`Total workers executed: ${workerCount}`);
Expand All @@ -54,6 +68,11 @@ async function runStressTest() {
console.log(`Average response time cv: ${avgResponseTime_cv.toFixed(4)} ms`);
console.log(`Variance cv: ${variance_cv.toFixed(4)} ms^2`);
console.log(`Standard deviation cv : ${stdDeviation_cv.toFixed(4)} ms`);

const failedJobs = results.reduce((acc, curr) => {
return acc + (curr.success === false ? 1 : 0);
}, 0);
console.log(`Failed jobs: ${failedJobs}`);
}

runStressTest();
2 changes: 1 addition & 1 deletion testing/backend-stress/src/phaseChange.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ async function simulate(userIndex) {
} catch (error) {
parentPort.postMessage({
userIndex,
responseTime: now() - startTime,
responseTime: 0,
success: false,
error: error.message
});
Expand Down

0 comments on commit 6f27359

Please sign in to comment.