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 cf7ed33 commit 2c381be
Show file tree
Hide file tree
Showing 4 changed files with 21 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
19 changes: 18 additions & 1 deletion testing/backend-stress/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,19 @@ 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: 0,
success: false
})
});
}

console.log(`Total workers executed: ${workerCount}`);
Expand All @@ -40,6 +52,11 @@ async function runStressTest() {
console.log(`Average response time: ${avgResponseTime.toFixed(4)} ms`);
console.log(`Variance: ${variance.toFixed(4)} ms^2`);
console.log(`Standard deviation: ${stdDeviation.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 2c381be

Please sign in to comment.