Skip to content

Commit

Permalink
test: add failing test case for #61 (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
ForbesLindesay committed Jan 3, 2023
1 parent 76480a9 commit 38a21b2
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions test/index.js
Expand Up @@ -520,3 +520,44 @@ test('stack traces - ready provided fn', async function () {
),
]);
});

test('https://github.com/ForbesLindesay/throat/issues/61', function () {
var batchSize = 256;
var batchCount = 256;
var lock = throat(1);
return runBatch(0);
function runBatch(batchIdx) {
if (batchIdx >= batchCount) return;
var jobs = [];
for (let i = 0; i < batchSize; i++) {
jobs.push(job());
}
const results = jobs.map((job) => lock(job));
function testNext(idx) {
if (idx >= jobs.length) return;
try {
assert(jobs[idx].isRun);
for (let i = idx + 1; i < jobs.length; i++) {
assert(jobs[i].isRun === false);
}
if (Math.random() > 0.5) {
jobs[idx].complete();
} else {
jobs[idx].fail();
}
} catch (ex) {
ex.message += `(batch: ${batchIdx}, job: ${idx})`;
throw ex;
}
return results[idx]
.catch(() => {
// ignore test error
})
.then(() => testNext(idx + 1));
}
return testNext(0).then(() => {
assert(jobs.every((job) => job.isRun));
return runBatch(batchIdx + 1);
});
}
});

0 comments on commit 38a21b2

Please sign in to comment.