Skip to content

Commit 106d38d

Browse files
committed
Add recursive deadlock test
Refs: metarhia#7 PR-URL: metarhia#18
1 parent 342bbd5 commit 106d38d

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const tests = [
66
'steps',
77
'exclusive',
88
'deadlock',
9+
'recursive-deadlock',
910
'thread-main',
1011
];
1112

test/recursive-deadlock.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
'use strict';
2+
3+
const assert = require('assert').strict;
4+
5+
const { locks } = require('..');
6+
7+
const TEST_TIMEOUT = 100;
8+
9+
module.exports = async () =>
10+
new Promise(resolve => {
11+
let flag1 = false;
12+
let flag2 = false;
13+
14+
(async () => {
15+
await locks.request('E', async () => {
16+
flag1 = true;
17+
await locks.request('E', async () => {
18+
flag2 = true;
19+
});
20+
});
21+
})();
22+
23+
(async () => {
24+
setTimeout(() => {
25+
assert.strictEqual(flag1, true);
26+
assert.strictEqual(flag2, false);
27+
resolve();
28+
}, TEST_TIMEOUT);
29+
})();
30+
});

0 commit comments

Comments
 (0)