From 106d38d2352e6eac969d37c5b64756105d6b1a4e Mon Sep 17 00:00:00 2001 From: Timur Shemsedinov Date: Sun, 15 Mar 2020 03:03:49 +0200 Subject: [PATCH] Add recursive deadlock test Refs: https://github.com/metarhia/web-locks/issues/7 PR-URL: https://github.com/metarhia/web-locks/pull/18 --- test.js | 1 + test/recursive-deadlock.js | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 test/recursive-deadlock.js 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); + })(); + });