Skip to content

Commit 13a25bb

Browse files
georgoldentshemsedinov
authored andcommitted
Improve Semaphore test quality
PR-URL: #108
1 parent ac83a75 commit 13a25bb

1 file changed

Lines changed: 8 additions & 10 deletions

File tree

test/semaphore.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ metatests.test('Semaphore timeout', async (test) => {
9090
test.end();
9191
});
9292

93-
metatests.test('Semaphore real life usage', (test) => {
93+
metatests.test('Semaphore real life usage', async (test) => {
9494
const semaphore = new Semaphore(CONCURRENCY, QUEUE_SIZE, TIMEOUT);
9595

9696
const useSemaphore = async () => {
@@ -108,17 +108,15 @@ metatests.test('Semaphore real life usage', (test) => {
108108
semaphore.leave();
109109
}
110110
};
111-
111+
const promises = [];
112112
for (let index = 1; index <= 20; index++) {
113-
useSemaphore();
113+
promises.push(useSemaphore());
114114
}
115-
116-
setTimeout(() => {
117-
test.strictSame(semaphore.empty, true);
118-
test.strictSame(semaphore.queue.length, 0);
119-
test.strictSame(semaphore.counter, CONCURRENCY);
120-
test.end();
121-
}, TIMEOUT + 1000);
115+
await Promise.all(promises);
116+
test.strictSame(semaphore.empty, true);
117+
test.strictSame(semaphore.queue.length, 0);
118+
test.strictSame(semaphore.counter, CONCURRENCY);
119+
test.end();
122120
});
123121

124122
metatests.test('Semaphore detailed counter fix test', async (test) => {

0 commit comments

Comments
 (0)