diff --git a/test.js b/test.js index e175e94..8f48423 100644 --- a/test.js +++ b/test.js @@ -6,6 +6,7 @@ const tests = [ 'steps', 'exclusive', 'deadlock', + 'recursive-deadlock', 'thread-main', ]; diff --git a/test/recursive-deadlock.js b/test/recursive-deadlock.js new file mode 100644 index 0000000..5ca8dca --- /dev/null +++ b/test/recursive-deadlock.js @@ -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); + })(); + });