Skip to content

Commit

Permalink
Add recursive deadlock test
Browse files Browse the repository at this point in the history
Refs: #7
PR-URL: #18
  • Loading branch information
tshemsedinov committed Mar 15, 2020
1 parent 342bbd5 commit 106d38d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const tests = [
'steps',
'exclusive',
'deadlock',
'recursive-deadlock',
'thread-main',
];

Expand Down
30 changes: 30 additions & 0 deletions test/recursive-deadlock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
'use strict';

const assert = require('assert').strict;

const { locks } = require('..');

const TEST_TIMEOUT = 100;

module.exports = async () =>
new Promise(resolve => {
let flag1 = false;
let flag2 = false;

(async () => {
await locks.request('E', async () => {
flag1 = true;
await locks.request('E', async () => {
flag2 = true;
});
});
})();

(async () => {
setTimeout(() => {
assert.strictEqual(flag1, true);
assert.strictEqual(flag2, false);
resolve();
}, TEST_TIMEOUT);
})();
});

0 comments on commit 106d38d

Please sign in to comment.