Skip to content

Commit c048cf2

Browse files
committed
Tests for Web Locks API
1 parent 6ac8282 commit c048cf2

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

test/locks.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
'use strict';
2+
3+
const common = require('@metarhia/common');
4+
const nodeVerion = common.between(process.version, 'v', '.');
5+
6+
if (nodeVerion >= 11) {
7+
const { isMainThread } = require('worker_threads');
8+
const { locks, Thread } = require('..');
9+
const metatests = require('metatests');
10+
11+
const sleep = msec => new Promise(res => setTimeout(res, msec));
12+
13+
if (isMainThread) {
14+
metatests.test('locks: enter and leave', test => {
15+
new Thread(__filename);
16+
new Thread(__filename);
17+
18+
setTimeout(() => {
19+
locks.request('A', async lock => {
20+
test.end();
21+
});
22+
}, 100);
23+
});
24+
} else {
25+
locks.request('A', async lock => {
26+
await sleep(100);
27+
});
28+
}
29+
}

0 commit comments

Comments
 (0)