From d30af90bae0a887feb013ca3aac9a0aae6566ced Mon Sep 17 00:00:00 2001 From: tshemsedinov Date: Wed, 27 Mar 2019 10:10:56 +0200 Subject: [PATCH] Simple test for Web Locks API Refs: https://github.com/metarhia/metasync/issues/416 --- test/locks.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 test/locks.js diff --git a/test/locks.js b/test/locks.js new file mode 100644 index 00000000..4fd1491d --- /dev/null +++ b/test/locks.js @@ -0,0 +1,28 @@ +'use strict'; + +const { isMainThread } = require('worker_threads'); +const { locks } = require('..'); +const { Thread } = locks; +const metatests = require('metatests'); + +const sleep = msec => + new Promise(resolve => { + setTimeout(resolve, msec); + }); + +if (isMainThread) { + metatests.test('locks: enter and leave', test => { + new Thread(); + new Thread(); + + setTimeout(() => { + locks.request('A', async lock => { + test.end(); + }); + }, 100); + }); +} else { + locks.request('A', async lock => { + await sleep(100); + }); +}