Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/src/util/node/test/lock.spec.ts
13401 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
import assert from 'assert';
6
import { suite, test } from 'vitest';
7
import { Lock } from '../../common/lock';
8
9
suite('Lock', async function () {
10
test('acquire and release', async function () {
11
const lock = new Lock();
12
await lock.acquire();
13
assert.strictEqual(lock.locked, true);
14
lock.release();
15
assert.strictEqual(lock.locked, false);
16
});
17
18
test('queueing', async function () {
19
const lock = new Lock();
20
await lock.acquire();
21
assert.strictEqual(lock.locked, true);
22
23
let released = false;
24
lock.acquire().then(() => {
25
released = true;
26
});
27
28
assert.strictEqual(released, false);
29
lock.release();
30
31
// wait 1 tick
32
await new Promise((resolve) => setTimeout(resolve, 0));
33
34
assert.strictEqual(released, true);
35
assert.strictEqual(lock.locked, true);
36
37
lock.release();
38
assert.strictEqual(lock.locked, false);
39
});
40
});
41
42