Skip to content

Commit

Permalink
#335 test: improve testing framework to be executable from the comman…
Browse files Browse the repository at this point in the history
…d line and only catch timeout errors
  • Loading branch information
Wolkenfarmer committed Oct 17, 2024
1 parent eceff0a commit 715b86d
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions testing/backend-stress/src/main.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import { Worker } from 'worker_threads';
import { resolve, dirname } from 'path';
import { fileURLToPath } from 'url';

const __dirname = dirname(fileURLToPath(import.meta.url))
const NUM_EXERCISES = 2

let results = [];
let workerCount = 0;

function startWorker(userIndex) {
const workerPath = resolve(__dirname, 'assignMaterial.js');

return new Promise((resolve, reject) => {
const worker = new Worker('./finishAction.js', {
const worker = new Worker(workerPath, {
workerData: { userIndex }
});

Expand All @@ -31,10 +36,11 @@ async function runStressTest() {
await Promise.race([
startWorker(i),
new Promise((_, reject) =>
setTimeout(() => reject(new Error('Timeout')), 60000)
setTimeout(() => reject(new Error('Timeout')), 90000)
)
])
.catch(() => {
.catch((e) => {
if (!e.message.includes('Timeout')) throw e;
results.push({
i,
responseTime_total: 0,
Expand Down

0 comments on commit 715b86d

Please sign in to comment.